Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update "what is a pure function" answer #308

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
349 changes: 178 additions & 171 deletions README.md
Original file line number Diff line number Diff line change
@@ -935,8 +935,15 @@
**[⬆ Back to Top](#table-of-contents)**

16. ### What is a pure function

A **Pure function** is a function where the return value is only determined by its arguments without any side effects. i.e, If you call a function with the same arguments 'n' number of times and 'n' number of places in the application then it will always return the same value.
A **Pure function** is a function that has 2 characteristics:
1- **Determinists**:
- For the same input, a pure function **will always return the smame output**.
- Doesn't depond on or modifying any external state.

2- **No Side Effects** such as:
- performing I/O operations such as logging to the console, making network request.
- Mutating its input arguments.
- Changing the DOM.

Let's take an example to see the difference between pure and impure functions,

@@ -961,7 +968,7 @@

**[⬆ Back to Top](#table-of-contents)**

17. ### What is the purpose of the let keyword
18. ### What is the purpose of the let keyword

The `let` statement declares a **block scope local variable**. Hence the variables defined with let keyword are limited in scope to the block, statement, or expression on which it is used. Whereas variables declared with the `var` keyword used to define a variable globally, or locally to an entire function regardless of block scope.

@@ -978,7 +985,7 @@

**[⬆ Back to Top](#table-of-contents)**

18. ### What is the difference between let and var
19. ### What is the difference between let and var

You can list out the differences in a tabular format

@@ -1007,13 +1014,13 @@

**[⬆ Back to Top](#table-of-contents)**

19. ### What is the reason to choose the name let as a keyword
20. ### What is the reason to choose the name let as a keyword

`let` is a mathematical statement that was adopted by early programming languages like **Scheme** and **Basic**. It has been borrowed from dozens of other languages that use `let` already as a traditional keyword as close to `var` as possible.

**[⬆ Back to Top](#table-of-contents)**

20. ### How do you redeclare variables in a switch block without an error
21. ### How do you redeclare variables in a switch block without an error

If you try to redeclare variables in a `switch block` then it will cause errors because there is only one block. For example, the below code block throws a syntax error as below,

@@ -1048,7 +1055,7 @@

**[⬆ Back to Top](#table-of-contents)**

21. ### What is the Temporal Dead Zone
22. ### What is the Temporal Dead Zone

The Temporal Dead Zone(TDZ) is a specific period or area of a block where a variable is inaccessible until it has been initialized with a value. This behavior in JavaScript that occurs when declaring a variable with the let and const keywords, but not with var. In ECMAScript 6, accessing a `let` or `const` variable before its declaration (within its scope) causes a ReferenceError.

@@ -1065,7 +1072,7 @@
**[⬆ Back to Top](#table-of-contents)**
22. ### What is an IIFE (Immediately Invoked Function Expression)
23. ### What is an IIFE (Immediately Invoked Function Expression)
IIFE (Immediately Invoked Function Expression) is a JavaScript function that runs as soon as it is defined. The signature of it would be as below,
@@ -1087,7 +1094,7 @@
**[⬆ Back to Top](#table-of-contents)**
23. ### How do you decode or encode a URL in JavaScript?
24. ### How do you decode or encode a URL in JavaScript?
`encodeURI()` function is used to encode an URL. This function requires a URL string as a parameter and return that encoded string.
`decodeURI()` function is used to decode an URL. This function requires an encoded URL string as parameter and return that decoded string.
@@ -1102,7 +1109,7 @@
**[⬆ Back to Top](#table-of-contents)**
24. ### What is memoization
25. ### What is memoization
Memoization is a functional programming technique which attempts to increase a function’s performance by caching its previously computed results. Each time a memoized function is called, its parameters are used to index the cache. If the data is present, then it can be returned, without executing the entire function. Otherwise the function is executed and then the result is added to the cache.
Let's take an example of adding function with memoization,
@@ -1130,7 +1137,7 @@

**[⬆ Back to Top](#table-of-contents)**

25. ### What is Hoisting
26. ### What is Hoisting

Hoisting is a JavaScript mechanism where variables, function declarations and classes are moved to the top of their scope before code execution. Remember that JavaScript only hoists declarations, not initialisation.
Let's take a simple example of variable hoisting,
@@ -1162,7 +1169,7 @@

**[⬆ Back to Top](#table-of-contents)**

26. ### What are classes in ES6
27. ### What are classes in ES6

In ES6, Javascript classes are primarily syntactic sugar over JavaScript’s existing prototype-based inheritance.
For example, the prototype based inheritance written in function expression as below,
@@ -1195,7 +1202,7 @@

**[⬆ Back to Top](#table-of-contents)**

27. ### What are closures
28. ### What are closures

A closure is the combination of a function bundled(enclosed) together with its lexical environment within which that function was declared. i.e, It is an inner function that has access to the outer or enclosing function’s variables, functions and other data even after the outer function has finished its execution. The closure has three scope chains.

@@ -1221,13 +1228,13 @@

**[⬆ Back to Top](#table-of-contents)**

28. ### What are modules
29. ### What are modules

Modules refer to small units of independent, reusable code and also act as the foundation of many JavaScript design patterns. Most of the JavaScript modules export an object literal, a function, or a constructor

**[⬆ Back to Top](#table-of-contents)**

29. ### Why do you need modules
30. ### Why do you need modules

Below are the list of benefits using modules in javascript ecosystem

@@ -1237,37 +1244,37 @@

**[⬆ Back to Top](#table-of-contents)**

30. ### What is scope in javascript
31. ### What is scope in javascript

Scope is the accessibility of variables, functions, and objects in some particular part of your code during runtime. In other words, scope determines the visibility of variables and other resources in areas of your code.

**[⬆ Back to Top](#table-of-contents)**

31. ### What is a service worker
32. ### What is a service worker

A Service worker is basically a script (JavaScript file) that runs in the background, separate from a web page and provides features that don't need a web page or user interaction. Some of the major features of service workers are Rich offline experiences(offline first web application development), periodic background syncs, push notifications, intercept and handle network requests and programmatically managing a cache of responses.

**[⬆ Back to Top](#table-of-contents)**

32. ### How do you manipulate DOM using a service worker
33. ### How do you manipulate DOM using a service worker

Service worker can't access the DOM directly. But it can communicate with the pages it controls by responding to messages sent via the `postMessage` interface, and those pages can manipulate the DOM.

**[⬆ Back to Top](#table-of-contents)**

33. ### How do you reuse information across service worker restarts
34. ### How do you reuse information across service worker restarts

The problem with service worker is that it gets terminated when not in use, and restarted when it's next needed, so you cannot rely on global state within a service worker's `onfetch` and `onmessage` handlers. In this case, service workers will have access to IndexedDB API in order to persist and reuse across restarts.

**[⬆ Back to Top](#table-of-contents)**

34. ### What is IndexedDB
35. ### What is IndexedDB

IndexedDB is a low-level API for client-side storage of larger amounts of structured data, including files/blobs. This API uses indexes to enable high-performance searches of this data.

**[⬆ Back to Top](#table-of-contents)**

35. ### What is web storage
36. ### What is web storage

Web storage is an API that provides a mechanism by which browsers can store key/value pairs locally within the user's browser, in a much more intuitive fashion than using cookies. The web storage provides two mechanisms for storing data on the client.

@@ -1276,13 +1283,13 @@

**[⬆ Back to Top](#table-of-contents)**

36. ### What is a post message
37. ### What is a post message

Post message is a method that enables cross-origin communication between Window objects.(i.e, between a page and a pop-up that it spawned, or between a page and an iframe embedded within it). Generally, scripts on different pages are allowed to access each other if and only if the pages follow same-origin policy(i.e, pages share the same protocol, port number, and host).

**[⬆ Back to Top](#table-of-contents)**

37. ### What is a Cookie
38. ### What is a Cookie

A cookie is a piece of data that is stored on your computer to be accessed by your browser. Cookies are saved as key/value pairs.
For example, you can create a cookie named username as below,
@@ -1295,7 +1302,7 @@

**[⬆ Back to Top](#table-of-contents)**

38. ### Why do you need a Cookie
39. ### Why do you need a Cookie

Cookies are used to remember information about the user profile(such as username). It basically involves two steps,

@@ -1304,7 +1311,7 @@

**[⬆ Back to Top](#table-of-contents)**

39. ### What are the options in a cookie
40. ### What are the options in a cookie

There are few below options available for a cookie,

@@ -1322,7 +1329,7 @@

**[⬆ Back to Top](#table-of-contents)**

40. ### How do you delete a cookie
41. ### How do you delete a cookie

You can delete a cookie by setting the expiry date as a passed date. You don't need to specify a cookie value in this case.
For example, you can delete a username cookie in the current page as below.
@@ -1336,7 +1343,7 @@

**[⬆ Back to Top](#table-of-contents)**

41. ### What are the differences between cookie, local storage and session storage
42. ### What are the differences between cookie, local storage and session storage

Below are some of the differences between cookie, local storage and session storage,

@@ -1351,13 +1358,13 @@

**[⬆ Back to Top](#table-of-contents)**

42. ### What is the main difference between localStorage and sessionStorage
43. ### What is the main difference between localStorage and sessionStorage

LocalStorage is the same as SessionStorage but it persists the data even when the browser is closed and reopened(i.e it has no expiration time) whereas in sessionStorage data gets cleared when the page session ends.

**[⬆ Back to Top](#table-of-contents)**

43. ### How do you access web storage
44. ### How do you access web storage

The Window object implements the `WindowLocalStorage` and `WindowSessionStorage` objects which has `localStorage`(window.localStorage) and `sessionStorage`(window.sessionStorage) properties respectively. These properties create an instance of the Storage object, through which data items can be set, retrieved and removed for a specific domain and storage type (session or local).
For example, you can read and write on local storage objects as below
@@ -1369,7 +1376,7 @@

**[⬆ Back to Top](#table-of-contents)**

44. ### What are the methods available on session storage
45. ### What are the methods available on session storage

The session storage provided methods for reading, writing and clearing the session data

@@ -1389,7 +1396,7 @@

**[⬆ Back to Top](#table-of-contents)**

45. ### What is a storage event and its event handler
46. ### What is a storage event and its event handler

The StorageEvent is an event that fires when a storage area has been changed in the context of another document. Whereas onstorage property is an EventHandler for processing storage events.
The syntax would be as below
@@ -1416,13 +1423,13 @@

**[⬆ Back to Top](#table-of-contents)**

46. ### Why do you need web storage
47. ### Why do you need web storage

Web storage is more secure, and large amounts of data can be stored locally, without affecting website performance. Also, the information is never transferred to the server. Hence this is a more recommended approach than Cookies.

**[⬆ Back to Top](#table-of-contents)**

47. ### How do you check web storage browser support
48. ### How do you check web storage browser support

You need to check browser support for localStorage and sessionStorage before using web storage,

@@ -1436,7 +1443,7 @@

**[⬆ Back to Top](#table-of-contents)**

48. ### How do you check web workers browser support
49. ### How do you check web workers browser support

You need to check browser support for web workers before using it

@@ -1450,7 +1457,7 @@

**[⬆ Back to Top](#table-of-contents)**

49. ### Give an example of a web worker
50. ### Give an example of a web worker

You need to follow below steps to start using web workers for counting example

@@ -1501,7 +1508,7 @@

**[⬆ Back to Top](#table-of-contents)**

50. ### What are the restrictions of web workers on DOM
51. ### What are the restrictions of web workers on DOM

WebWorkers don't have access to below javascript objects since they are defined in an external files
@@ -1511,7 +1518,7 @@
**[⬆ Back to Top](#table-of-contents)**
51. ### What is a promise
52. ### What is a promise
A promise is an object that may produce a single value some time in the future with either a resolved value or a reason that it’s not resolved (i.e. rejected, that means for example, due to a network error). It will be in one of the 3 possible states: fulfilled, rejected, or pending.
@@ -1544,13 +1551,13 @@
**[⬆ Back to Top](#table-of-contents)**
52. ### Why do you need a promise
53. ### Why do you need a promise
Promises are used to handle asynchronous operations. They provide an alternative approach for callbacks by reducing the callback hell and writing the cleaner code.
**[⬆ Back to Top](#table-of-contents)**
53. ### What are the three states of promise
54. ### What are the three states of promise
Promises have three states:
@@ -1560,7 +1567,7 @@
**[⬆ Back to Top](#table-of-contents)**
54. ### What is a callback function
55. ### What is a callback function
A callback function is a function passed into another function as an argument. This function is invoked inside the outer function to complete an action.
Let's take a simple example of how to use callback function
@@ -1580,7 +1587,7 @@
**[⬆ Back to Top](#table-of-contents)**
55. ### Why do we need callbacks
56. ### Why do we need callbacks
The callbacks are needed because javascript is an event driven language. That means instead of waiting for a response, javascript will keep executing while listening for other events.
Let's take an example with the first function invoking an API call(simulated by setTimeout) and the next function which logs the message.
@@ -1607,7 +1614,7 @@
**[⬆ Back to Top](#table-of-contents)**
56. ### What is a callback hell
57. ### What is a callback hell
Callback Hell is an anti-pattern with multiple nested callbacks which makes code hard to read and debug when dealing with asynchronous logic. The callback hell looks like below,
@@ -1625,13 +1632,13 @@
**[⬆ Back to Top](#table-of-contents)**
57. ### What are server-sent events
58. ### What are server-sent events
Server-sent events (SSE) is a server push technology enabling a browser to receive automatic updates from a server via HTTP connection without resorting to polling. These are a one way communications channel - events flow from server to client only. This has been used in Facebook/Twitter/X updates, stock price updates, news feeds etc.
**[⬆ Back to Top](#table-of-contents)**
58. ### How do you receive server-sent event notifications
59. ### How do you receive server-sent event notifications
The EventSource object is used to receive server-sent event notifications. For example, you can receive messages from server as below,
@@ -1646,7 +1653,7 @@
**[⬆ Back to Top](#table-of-contents)**
59. ### How do you check browser support for server-sent events
60. ### How do you check browser support for server-sent events
You can perform browser support for server-sent events before using it as below,
@@ -1660,7 +1667,7 @@

**[⬆ Back to Top](#table-of-contents)**

60. ### What are the events available for server sent events
61. ### What are the events available for server sent events

Below are the list of events available for server sent events
| Event | Description |
@@ -1671,7 +1678,7 @@

**[⬆ Back to Top](#table-of-contents)**

61. ### What are the main rules of promise
62. ### What are the main rules of promise

A promise must follow a specific set of rules:

@@ -1682,7 +1689,7 @@

**[⬆ Back to Top](#table-of-contents)**

62. ### What is callback in callback
63. ### What is callback in callback

You can nest one callback inside in another callback to execute the actions sequentially one by one. This is known as callbacks in callbacks. Beware, too many levels of nesting lead to [Callback hell](https://github.com/ckpinguin/javascript-interview-questions/tree/master?tab=readme-ov-file#what-is-a-callback-hell)

@@ -1703,7 +1710,7 @@

**[⬆ Back to Top](#table-of-contents)**

63. ### What is promise chaining
64. ### What is promise chaining

The process of executing a sequence of asynchronous tasks one after another using promises is known as Promise chaining. Let's take an example of promise chaining for calculating the final result,
@@ -1734,7 +1741,7 @@
**[⬆ Back to Top](#table-of-contents)**
64. ### What is promise.all
65. ### What is promise.all
Promise.all is a promise that takes an array of promises as an input (an iterable), and it gets resolved when all the promises get resolved or any one of them gets rejected. For example, the syntax of promise.all method is below,
@@ -1746,7 +1753,7 @@
**[⬆ Back to Top](#table-of-contents)**
65. ### What is the purpose of the race method in promise
66. ### What is the purpose of the race method in promise
Promise.race() method will return the promise instance which is firstly resolved or rejected. Let's take an example of race() method where promise2 is resolved first

@@ -1765,19 +1772,19 @@

**[⬆ Back to Top](#table-of-contents)**

66. ### What is a strict mode in javascript
67. ### What is a strict mode in javascript

Strict Mode is a new feature in ECMAScript 5 that allows you to place a program, or a function, in a “strict” operating context. This way it prevents certain actions from being taken and throws more exceptions. The literal expression `"use strict";` instructs the browser to use the javascript code in the Strict mode. This also enables block-scoped variables.

**[⬆ Back to Top](#table-of-contents)**

67. ### Why do you need strict mode
68. ### Why do you need strict mode

Strict mode is useful to write "secure" JavaScript by notifying "bad syntax" into real errors. For example, it eliminates accidentally creating a global variable by throwing an error and also throws an error for assignment to a non-writable property, a getter-only property, a non-existing property, a non-existing variable, or a non-existing object.

**[⬆ Back to Top](#table-of-contents)**

68. ### How do you declare strict mode
69. ### How do you declare strict mode

The strict mode is declared by adding "use strict"; to the beginning of a script or a function.
If declared at the beginning of a script, it has global scope.
@@ -1801,7 +1808,7 @@
**[⬆ Back to Top](#table-of-contents)**
69. ### What is the purpose of double exclamation
70. ### What is the purpose of double exclamation
The double exclamation or negation(!!) ensures the resulting type is a boolean. If it was falsey (e.g. 0, null, undefined, etc.), it will be false, otherwise, it will be true.
For example, you can test IE version using this expression as below,
@@ -1822,7 +1829,7 @@
**[⬆ Back to Top](#table-of-contents)**
70. ### What is the purpose of the delete operator
71. ### What is the purpose of the delete operator
The delete operator is used to delete the property as well as its value.
@@ -1835,7 +1842,7 @@
**[⬆ Back to Top](#table-of-contents)**
71. ### What is typeof operator
72. ### What is typeof operator
You can use the JavaScript typeof operator to find the type of a JavaScript variable. It returns the type of a variable or an expression.
@@ -1847,7 +1854,7 @@
**[⬆ Back to Top](#table-of-contents)**
72. ### What is undefined property
73. ### What is undefined property
The undefined property indicates that a variable has not been assigned a value, or declared but not initialized at all. The type of undefined value is undefined too.
@@ -1864,7 +1871,7 @@
**[⬆ Back to Top](#table-of-contents)**
73. ### What is null value
74. ### What is null value
The value null represents the intentional absence of any object value. It is one of JavaScript's primitive values. The type of null value is object.
You can empty the variable by setting the value to null.
@@ -1876,7 +1883,7 @@
**[⬆ Back to Top](#table-of-contents)**
74. ### What is the difference between null and undefined
75. ### What is the difference between null and undefined
Below are the main differences between null and undefined,
@@ -1890,7 +1897,7 @@
**[⬆ Back to Top](#table-of-contents)**
75. ### What is eval
76. ### What is eval
The eval() function evaluates JavaScript code represented as a string. The string can be a JavaScript expression, variable, statement, or sequence of statements.
@@ -1900,7 +1907,7 @@
**[⬆ Back to Top](#table-of-contents)**
76. ### What is the difference between window and document
77. ### What is the difference between window and document
Below are the main differences between window and document,
@@ -1912,7 +1919,7 @@
**[⬆ Back to Top](#table-of-contents)**
77. ### How do you access history in javascript
78. ### How do you access history in javascript
The window.history object contains the browser's history. You can load previous and next URLs in the history using back() and next() methods.
@@ -1929,7 +1936,7 @@
**[⬆ Back to Top](#table-of-contents)**
78. ### How do you detect caps lock key turned on or not
79. ### How do you detect caps lock key turned on or not
The `mouseEvent getModifierState()` is used to return a boolean value that indicates whether the specified modifier key is activated or not. The modifiers such as CapsLock, ScrollLock and NumLock are activated when they are clicked, and deactivated when they are clicked again.
@@ -1955,7 +1962,7 @@
**[⬆ Back to Top](#table-of-contents)**
79. ### What is isNaN
80. ### What is isNaN
The isNaN() function is used to determine whether a value is an illegal number (Not-a-Number) or not. i.e, This function returns true if the value equates to NaN. Otherwise it returns false.
@@ -1966,7 +1973,7 @@
**[⬆ Back to Top](#table-of-contents)**
80. ### What are the differences between undeclared and undefined variables
81. ### What are the differences between undeclared and undefined variables
Below are the major differences between undeclared(not defined) and undefined variables,
@@ -1985,7 +1992,7 @@
**[⬆ Back to Top](#table-of-contents)**
81. ### What are global variables
82. ### What are global variables
Global variables are those that are available throughout the length of the code without any scope. The var keyword is used to declare a local variable but if you omit it then it will become global variable
@@ -1995,13 +2002,13 @@
**[⬆ Back to Top](#table-of-contents)**
82. ### What are the problems with global variables
83. ### What are the problems with global variables
The problem with global variables is the conflict of variable names of local and global scope. It is also difficult to debug and test the code that relies on global variables.
**[⬆ Back to Top](#table-of-contents)**
83. ### What is NaN property
84. ### What is NaN property
The NaN property is a global property that represents "Not-a-Number" value. i.e, It indicates that a value is not a legal number. It is very rare to use NaN in a program but it can be used as return value for few cases
@@ -2012,7 +2019,7 @@
**[⬆ Back to Top](#table-of-contents)**
84. ### What is the purpose of isFinite function
85. ### What is the purpose of isFinite function
The isFinite() function is used to determine whether a number is a finite, legal number. It returns false if the value is +infinity, -infinity, or NaN (Not-a-Number), otherwise it returns true.
@@ -2026,7 +2033,7 @@
**[⬆ Back to Top](#table-of-contents)**
85. ### What is an event flow
86. ### What is an event flow
Event flow is the order in which event is received on the web page. When you click an element that is nested in various other elements, before your click actually reaches its destination, or target element, it must trigger the click event for each of its parent elements first, starting at the top with the global window object.
@@ -2037,7 +2044,7 @@
**[⬆ Back to Top](#table-of-contents)**
86. ### What is event bubbling
87. ### What is event bubbling
Event bubbling is a type of event propagation where the event first triggers on the innermost target element, and then successively triggers on the ancestors (parents) of the target element in the same nesting hierarchy till it reaches the outermost DOM element(i.e, global window object).
@@ -2068,7 +2075,7 @@
**[⬆ Back to Top](#table-of-contents)**
87. ### What is event capturing
88. ### What is event capturing
Event capturing is a type of event propagation where the event is first captured by the outermost element, and then successively triggers on the descendants (children) of the target element in the same nesting hierarchy till it reaches the innermost target DOM element.
@@ -2100,7 +2107,7 @@
**[⬆ Back to Top](#table-of-contents)**
88. ### How do you submit a form using JavaScript
89. ### How do you submit a form using JavaScript
You can submit a form using `document.forms[0].submit()`. All the form input's information is submitted using onsubmit event handler
@@ -2112,7 +2119,7 @@
**[⬆ Back to Top](#table-of-contents)**
89. ### How do you find operating system details
90. ### How do you find operating system details
The window.navigator object contains information about the visitor's browser OS details. Some of the OS properties are available under platform property,
@@ -2122,13 +2129,13 @@
**[⬆ Back to Top](#table-of-contents)**
90. ### What is the difference between document load and DOMContentLoaded events
91. ### What is the difference between document load and DOMContentLoaded events
The `DOMContentLoaded` event is fired when the initial HTML document has been completely loaded and parsed, without waiting for assets(stylesheets, images, and subframes) to finish loading. Whereas The load event is fired when the whole page has loaded, including all dependent resources(stylesheets, images).
**[⬆ Back to Top](#table-of-contents)**
91. ### What is the difference between native, host and user objects
92. ### What is the difference between native, host and user objects
`Native objects` are objects that are part of the JavaScript language defined by the ECMAScript specification. For example, String, Math, RegExp, Object, Function etc core objects defined in the ECMAScript spec.
`Host objects` are objects provided by the browser or runtime environment (Node).
@@ -2138,7 +2145,7 @@
**[⬆ Back to Top](#table-of-contents)**
92. ### What are the tools or techniques used for debugging JavaScript code
93. ### What are the tools or techniques used for debugging JavaScript code
You can use below tools or techniques for debugging javascript
@@ -2148,7 +2155,7 @@
**[⬆ Back to Top](#table-of-contents)**
93. ### What are the pros and cons of promises over callbacks
94. ### What are the pros and cons of promises over callbacks
Below are the list of pros and cons of promises over callbacks,
@@ -2166,7 +2173,7 @@
**[⬆ Back to Top](#table-of-contents)**
94. ### What is the difference between an attribute and a property
95. ### What is the difference between an attribute and a property
Attributes are defined on the HTML markup whereas properties are defined on the DOM. For example, the below HTML element has 2 attributes: `type` and `value`,
@@ -2191,13 +2198,13 @@
**[⬆ Back to Top](#table-of-contents)**
95. ### What is same-origin policy
96. ### What is same-origin policy
The same-origin policy is a policy that prevents JavaScript from making requests across domain boundaries. An origin is defined as a combination of URI scheme, hostname, and port number. If you enable this policy then it prevents a malicious script on one page from obtaining access to sensitive data on another web page using Document Object Model(DOM).
**[⬆ Back to Top](#table-of-contents)**
96. ### What is the purpose of void 0
97. ### What is the purpose of void 0
Void(0) is used to prevent the page from refreshing. This will be helpful to eliminate the unwanted side-effect, because it will return the undefined primitive value. It is commonly used for HTML documents that use href="JavaScript:Void(0);" within an `<a>` element. i.e, when you click a link, the browser loads a new page or refreshes the same page. But this behavior will be prevented using this expression.
For example, the below link notify the message without reloading the page
@@ -2210,25 +2217,25 @@
**[⬆ Back to Top](#table-of-contents)**
97. ### Is JavaScript a compiled or interpreted language
98. ### Is JavaScript a compiled or interpreted language
JavaScript is an interpreted language, not a compiled language. An interpreter in the browser reads over the JavaScript code, interprets each line, and runs it. Nowadays modern browsers use a technology known as Just-In-Time (JIT) compilation, which compiles JavaScript to executable bytecode just as it is about to run.
**[⬆ Back to Top](#table-of-contents)**
98. ### Is JavaScript a case-sensitive language
99. ### Is JavaScript a case-sensitive language
Yes, JavaScript is a case sensitive language. The language keywords, variables, function & object names, and any other identifiers must always be typed with a consistent capitalization of letters.
**[⬆ Back to Top](#table-of-contents)**
99. ### Is there any relation between Java and JavaScript
100. ### Is there any relation between Java and JavaScript
No, they are entirely two different programming languages and have nothing to do with each other. But both of them are Object Oriented Programming languages and like many other languages, they follow similar syntax for basic features(if, else, for, switch, break, continue etc).
**[⬆ Back to Top](#table-of-contents)**
100. ### What are events
101. ### What are events
Events are "things" that happen to HTML elements. When JavaScript is used in HTML pages, JavaScript can `react` on these events. Some of the examples of HTML events are,
@@ -2256,13 +2263,13 @@
**[⬆ Back to Top](#table-of-contents)**
101. ### Who created javascript
102. ### Who created javascript
JavaScript was created by Brendan Eich in 1995 during his time at Netscape Communications. Initially it was developed under the name `Mocha`, but later the language was officially called `LiveScript` when it first shipped in beta releases of Netscape.
**[⬆ Back to Top](#table-of-contents)**
102. ### What is the use of preventDefault method
103. ### What is the use of preventDefault method
The preventDefault() method cancels the event if it is cancelable, meaning that the default action or behaviour that belongs to the event will not occur. For example, prevent form submission when clicking on submit button and prevent opening the page URL when clicking on hyperlink are some common use cases.
@@ -2278,7 +2285,7 @@
**[⬆ Back to Top](#table-of-contents)**
103. ### What is the use of stopPropagation method
104. ### What is the use of stopPropagation method
The stopPropagation method is used to stop the event from bubbling up the event chain. For example, the below nested divs with stopPropagation method prevents default event propagation when clicking on nested div(Div1)
@@ -2302,7 +2309,7 @@
**[⬆ Back to Top](#table-of-contents)**
104. ### What are the steps involved in return false usage
105. ### What are the steps involved in return false usage
The return false statement in event handlers performs the below steps,
@@ -2312,15 +2319,15 @@
**[⬆ Back to Top](#table-of-contents)**
105. ### What is BOM
106. ### What is BOM
The Browser Object Model (BOM) allows JavaScript to "talk to" the browser. It consists of the objects navigator, history, screen, location and document which are children of the window. The Browser Object Model is not standardized and can change based on different browsers.
![Screenshot](images/bom.png)
**[⬆ Back to Top](#table-of-contents)**
106. ### What is the use of setTimeout
107. ### What is the use of setTimeout
The setTimeout() method is used to call a function or evaluate an expression after a specified number of milliseconds. For example, let's log a message after 2 seconds using setTimeout method,
@@ -2332,7 +2339,7 @@
**[⬆ Back to Top](#table-of-contents)**
107. ### What is the use of setInterval
108. ### What is the use of setInterval
The setInterval() method is used to call a function or evaluate an expression at specified intervals (in milliseconds). For example, let's log a message after 2 seconds using setInterval method,
@@ -2344,13 +2351,13 @@
**[⬆ Back to Top](#table-of-contents)**
108. ### Why is JavaScript treated as Single threaded
109. ### Why is JavaScript treated as Single threaded
JavaScript is a single-threaded language. Because the language specification does not allow the programmer to write code so that the interpreter can run parts of it in parallel in multiple threads or processes. Whereas languages like java, go, C++ can make multi-threaded and multi-process programs.
**[⬆ Back to Top](#table-of-contents)**
109. ### What is an event delegation
110. ### What is an event delegation
Event delegation is a technique for listening to events where you delegate a parent element as the listener for all of the events that happen inside it.
@@ -2372,19 +2379,19 @@
**[⬆ Back to Top](#table-of-contents)**
110. ### What is ECMAScript
111. ### What is ECMAScript
ECMAScript is the scripting language that forms the basis of JavaScript. ECMAScript standardized by the ECMA International standards organization in the ECMA-262 and ECMA-402 specifications. The first edition of ECMAScript was released in 1997.
**[⬆ Back to Top](#table-of-contents)**
111. ### What is JSON
112. ### What is JSON
JSON (JavaScript Object Notation) is a lightweight format that is used for data interchanging. It is based on a subset of JavaScript language in the way objects are built in JavaScript.
**[⬆ Back to Top](#table-of-contents)**
112. ### What are the syntax rules of JSON
113. ### What are the syntax rules of JSON
Below are the list of syntax rules of JSON
@@ -2395,7 +2402,7 @@
**[⬆ Back to Top](#table-of-contents)**
113. ### What is the purpose JSON stringify
114. ### What is the purpose JSON stringify
When sending data to a web server, the data has to be in a string format. You can achieve this by converting JSON object into a string using stringify() method.
@@ -2407,7 +2414,7 @@
**[⬆ Back to Top](#table-of-contents)**
114. ### How do you parse JSON string
115. ### How do you parse JSON string
When receiving the data from a web server, the data is always in a string format. But you can convert this string value to a javascript object using parse() method.
@@ -2419,19 +2426,19 @@
**[⬆ Back to Top](#table-of-contents)**
115. ### Why do you need JSON
116. ### Why do you need JSON
When exchanging data between a browser and a server, the data can only be text. Since JSON is text only, it can easily be sent to and from a server, and used as a data format by any programming language.
**[⬆ Back to Top](#table-of-contents)**
116. ### What are PWAs
117. ### What are PWAs
Progressive web applications (PWAs) are a type of mobile app delivered through the web, built using common web technologies including HTML, CSS and JavaScript. These PWAs are deployed to servers, accessible through URLs, and indexed by search engines.
**[⬆ Back to Top](#table-of-contents)**
117. ### What is the purpose of clearTimeout method
118. ### What is the purpose of clearTimeout method
The clearTimeout() function is used in javascript to clear the timeout which has been set by setTimeout()function before that. i.e, The return value of setTimeout() function is stored in a variable and it’s passed into the clearTimeout() function to clear the timer.
@@ -2456,7 +2463,7 @@
**[⬆ Back to Top](#table-of-contents)**
118. ### What is the purpose of clearInterval method
119. ### What is the purpose of clearInterval method
The clearInterval() function is used in javascript to clear the interval which has been set by setInterval() function. i.e, The return value returned by setInterval() function is stored in a variable and it’s passed into the clearInterval() function to clear the interval.
@@ -2481,7 +2488,7 @@
**[⬆ Back to Top](#table-of-contents)**
119. ### How do you redirect new page in javascript
120. ### How do you redirect new page in javascript
In vanilla javascript, you can redirect to a new page using the `location` property of window object. The syntax would be as follows,
@@ -2493,7 +2500,7 @@
**[⬆ Back to Top](#table-of-contents)**
120. ### How do you check whether a string contains a substring
121. ### How do you check whether a string contains a substring
There are 3 possible ways to check whether a string contains a substring or not,
@@ -2523,7 +2530,7 @@
**[⬆ Back to Top](#table-of-contents)**
121. ### How do you validate an email in javascript
122. ### How do you validate an email in javascript
You can validate an email in javascript using regular expressions. It is recommended to do validations on the server side instead of the client side. Because the javascript can be disabled on the client side.
@@ -2539,7 +2546,7 @@
The above regular expression accepts unicode characters.
122. ### How do you get the current url with javascript
123. ### How do you get the current url with javascript
You can use `window.location.href` expression to get the current url path and you can use the same expression for updating the URL too. You can also use `document.URL` for read-only purposes but this solution has issues in FF.
@@ -2549,7 +2556,7 @@
**[⬆ Back to Top](#table-of-contents)**
123. ### What are the various url properties of location object
124. ### What are the various url properties of location object
The below `Location` object properties can be used to access URL components of the page,
@@ -2564,7 +2571,7 @@
**[⬆ Back to Top](#table-of-contents)**
124. ### How do get query string values in javascript
125. ### How do get query string values in javascript
You can use URLSearchParams to get query string values in javascript. Let's see an example to get the client code value from URL query string,
@@ -2575,7 +2582,7 @@
**[⬆ Back to Top](#table-of-contents)**
125. ### How do you check if a key exists in an object
126. ### How do you check if a key exists in an object
You can check whether a key exists in an object or not using three approaches,
@@ -2610,7 +2617,7 @@
**[⬆ Back to Top](#table-of-contents)**
126. ### How do you loop through or enumerate javascript object
127. ### How do you loop through or enumerate javascript object
You can use the `for-in` loop to loop through javascript object. You can also make sure that the key you get is an actual property of an object, and doesn't come from the prototype using `hasOwnProperty` method.
@@ -2630,7 +2637,7 @@
**[⬆ Back to Top](#table-of-contents)**
127. ### How do you test for an empty object
128. ### How do you test for an empty object
There are different solutions based on ECMAScript versions
@@ -2662,7 +2669,7 @@
**[⬆ Back to Top](#table-of-contents)**
128. ### What is an arguments object
129. ### What is an arguments object
The arguments object is an Array-like object accessible inside functions that contains the values of the arguments passed to that function. For example, let's see how to use arguments object inside sum function,
@@ -2686,7 +2693,7 @@
**[⬆ Back to Top](#table-of-contents)**
129. ### How do you make first letter of the string in an uppercase
130. ### How do you make first letter of the string in an uppercase
You can create a function which uses a chain of string methods such as charAt, toUpperCase and slice methods to generate a string with the first letter in uppercase.
@@ -2698,7 +2705,7 @@
**[⬆ Back to Top](#table-of-contents)**
130. ### What are the pros and cons of for loops
131. ### What are the pros and cons of for loops
The for-loop is a commonly used iteration syntax in javascript. It has both pros and cons
@@ -2715,7 +2722,7 @@
**[⬆ Back to Top](#table-of-contents)**
131. ### How do you display the current date in javascript
132. ### How do you display the current date in javascript
You can use `new Date()` to generate a new Date object containing the current date and time. For example, let's display the current date in mm/dd/yyyy
@@ -2731,7 +2738,7 @@
**[⬆ Back to Top](#table-of-contents)**
132. ### How do you compare two date objects
133. ### How do you compare two date objects
You need to use date.getTime() method in order to compare unix timestamp values
@@ -2744,7 +2751,7 @@
**[⬆ Back to Top](#table-of-contents)**
133. ### How do you check if a string starts with another string
134. ### How do you check if a string starts with another string
You can use ECMAScript 6's `String.prototype.startsWith()` method to check if a string starts with another string or not. But it is not yet supported in all browsers. Let's see an example to see this usage,
@@ -2755,7 +2762,7 @@
**[⬆ Back to Top](#table-of-contents)**
134. ### How do you trim a string in javascript
135. ### How do you trim a string in javascript
JavaScript provided a trim method on string types to trim any whitespaces present at the beginning or ending of the string.
@@ -2779,7 +2786,7 @@
**[⬆ Back to Top](#table-of-contents)**
135. ### How do you add a key value pair in javascript
136. ### How do you add a key value pair in javascript
There are two possible solutions to add new properties to an object.
@@ -2806,7 +2813,7 @@
**[⬆ Back to Top](#table-of-contents)**
136. ### Is the !-- notation represents a special operator
137. ### Is the !-- notation represents a special operator
No,that's not a special operator. But it is a combination of 2 standard operators one after the other,
@@ -2817,7 +2824,7 @@
**[⬆ Back to Top](#table-of-contents)**
137. ### How do you assign default values to variables
138. ### How do you assign default values to variables
You can use the logical or operator `||` in an assignment expression to provide a default value. The syntax looks like as below,
@@ -2829,7 +2836,7 @@
**[⬆ Back to Top](#table-of-contents)**
138. ### How do you define multiline strings
139. ### How do you define multiline strings
You can define multiline string literals using the '\n' character followed by line terminator('\').
@@ -2843,13 +2850,13 @@
**[⬆ Back to Top](#table-of-contents)**
139. ### What is an app shell model
140. ### What is an app shell model
An application shell (or app shell) architecture is one way to build a Progressive Web App that reliably and instantly loads on your users' screens, similar to what you see in native applications. It is useful for getting some initial HTML to the screen fast without a network.
**[⬆ Back to Top](#table-of-contents)**
140. ### Can we define properties for functions
141. ### Can we define properties for functions
Yes, we can define properties for functions because functions are also objects.
@@ -2867,7 +2874,7 @@
**[⬆ Back to Top](#table-of-contents)**
141. ### What is the way to find the number of parameters expected by a function
142. ### What is the way to find the number of parameters expected by a function
You can use `function.length` syntax to find the number of parameters expected by a function. Let's take an example of `sum` function to calculate the sum of numbers,

@@ -2880,7 +2887,7 @@
**[⬆ Back to Top](#table-of-contents)**
142. ### What is a polyfill
143. ### What is a polyfill
A polyfill is a piece of JS code used to provide modern functionality on older browsers that do not natively support it. For example, Silverlight plugin polyfill can be used to mimic the functionality of an HTML Canvas element on Microsoft Internet Explorer 7.
@@ -2890,7 +2897,7 @@
**[⬆ Back to Top](#table-of-contents)**
143. ### What are break and continue statements
144. ### What are break and continue statements
The break statement is used to "jump out" of a loop. i.e, It breaks the loop and continues executing the code after the loop.
@@ -2916,7 +2923,7 @@
**[⬆ Back to Top](#table-of-contents)**
144. ### What are js labels
145. ### What are js labels
The label statement allows us to name loops and blocks in JavaScript. We can then use these labels to refer back to the code later. For example, the below code with labels avoids printing the numbers when they are same,
@@ -2940,7 +2947,7 @@
**[⬆ Back to Top](#table-of-contents)**
145. ### What are the benefits of keeping declarations at the top
146. ### What are the benefits of keeping declarations at the top
It is recommended to keep all declarations at the top of each script or function. The benefits of doing this are,
@@ -2951,7 +2958,7 @@
**[⬆ Back to Top](#table-of-contents)**
146. ### What are the benefits of initializing variables
147. ### What are the benefits of initializing variables
It is recommended to initialize variables because of the below benefits,
@@ -2961,7 +2968,7 @@
**[⬆ Back to Top](#table-of-contents)**
147. ### What are the recommendations to create new object
148. ### What are the recommendations to create new object
It is recommended to avoid creating new objects using `new Object()`. Instead you can initialize values based on it's type to create the objects.
@@ -2987,7 +2994,7 @@
**[⬆ Back to Top](#table-of-contents)**
148. ### How do you define JSON arrays
149. ### How do you define JSON arrays
JSON arrays are written inside square brackets and arrays contain javascript objects. For example, the JSON array of users would be as below,
@@ -3001,7 +3008,7 @@
**[⬆ Back to Top](#table-of-contents)**
149. ### How do you generate random integers
150. ### How do you generate random integers
You can use Math.random() with Math.floor() to return random integers. For example, if you want generate random integers between 1 to 10, the multiplication factor should be 10,
@@ -3014,7 +3021,7 @@
**[⬆ Back to Top](#table-of-contents)**
150. ### Can you write a random integers function to print integers within a range
151. ### Can you write a random integers function to print integers within a range
Yes, you can create a proper random function to return a random number between min and max (both included)
@@ -3028,25 +3035,25 @@
**[⬆ Back to Top](#table-of-contents)**
151. ### What is tree shaking
152. ### What is tree shaking
Tree shaking is a form of dead code elimination. It means that unused modules will not be included in the bundle during the build process and for that it relies on the static structure of ES2015 module syntax,( i.e. import and export). Initially this has been popularized by the ES2015 module bundler `rollup`.
**[⬆ Back to Top](#table-of-contents)**
152. ### What is the need of tree shaking
153. ### What is the need of tree shaking
Tree Shaking can significantly reduce the code size in any application. i.e, The less code we send over the wire the more performant the application will be. For example, if we just want to create a “Hello World” Application using SPA frameworks then it will take around a few MBs, but by tree shaking it can bring down the size to just a few hundred KBs. Tree shaking is implemented in Rollup and Webpack bundlers.
**[⬆ Back to Top](#table-of-contents)**
153. ### Is it recommended to use eval
154. ### Is it recommended to use eval
No, it allows arbitrary code to be run which causes a security problem. As we know that the eval() function is used to run text as code. In most of the cases, it should not be necessary to use it.
**[⬆ Back to Top](#table-of-contents)**
154. ### What is a Regular Expression
155. ### What is a Regular Expression
A regular expression is a sequence of characters that forms a search pattern. You can use this search pattern for searching data in a text. These can be used to perform all types of text search and text replace operations. Let's see the syntax format now,
@@ -3062,7 +3069,7 @@
**[⬆ Back to Top](#table-of-contents)**
155. ### What are the string methods that accept Regular expression
156. ### What are the string methods that accept Regular expression
There are six string methods: search(), replace(), replaceAll(), match(), matchAll(), and split().
@@ -3098,7 +3105,7 @@
**[⬆ Back to Top](#table-of-contents)**
156. ### What are modifiers in regular expression
157. ### What are modifiers in regular expression
Modifiers can be used to perform case-insensitive and global searches. Let's list down some of the modifiers,
@@ -3118,7 +3125,7 @@
**[⬆ Back to Top](#table-of-contents)**
157. ### What are regular expression patterns
158. ### What are regular expression patterns
Regular Expressions provide a group of patterns in order to match characters. Basically they are categorized into 3 types,
@@ -3140,7 +3147,7 @@
**[⬆ Back to Top](#table-of-contents)**
158. ### What is a RegExp object
159. ### What is a RegExp object
RegExp object is a regular expression object with predefined properties and methods. Let's see the simple usage of RegExp object,
@@ -3152,7 +3159,7 @@
**[⬆ Back to Top](#table-of-contents)**
159. ### How do you search a string for a pattern
160. ### How do you search a string for a pattern
You can use the test() method of regular expression in order to search a string for a pattern, and return true or false depending on the result.
@@ -3163,7 +3170,7 @@
**[⬆ Back to Top](#table-of-contents)**
160. ### What is the purpose of exec method
161. ### What is the purpose of exec method
The purpose of exec method is similar to test method but it executes a search for a match in a specified string and returns a result array, or null instead of returning true/false.
@@ -3174,7 +3181,7 @@
**[⬆ Back to Top](#table-of-contents)**
161. ### How do you change the style of a HTML element
162. ### How do you change the style of a HTML element
You can change inline style or classname of a HTML element using javascript
@@ -3192,13 +3199,13 @@
**[⬆ Back to Top](#table-of-contents)**
162. ### What would be the result of 1+2+'3'
163. ### What would be the result of 1+2+'3'
The output is going to be `33`. Since `1` and `2` are numeric values, the result of the first two digits is going to be a numeric value `3`. The next digit is a string type value because of that the addition of numeric value `3` and string type value `3` is just going to be a concatenation value `33`. Other operationrs like `3 * '3'` do yield correct results because the string is coerced into a number.
**[⬆ Back to Top](#table-of-contents)**
163. ### What is a debugger statement
164. ### What is a debugger statement
The debugger statement invokes any available debugging functionality, such as setting a breakpoint. If no debugging functionality is available, this statement has no effect.
For example, in the below function a debugger statement has been inserted. So
@@ -3214,13 +3221,13 @@
**[⬆ Back to Top](#table-of-contents)**
164. ### What is the purpose of breakpoints in debugging
165. ### What is the purpose of breakpoints in debugging
You can set breakpoints in the javascript code once the debugger statement is executed and the debugger window pops up. At each breakpoint, javascript will stop executing, and let you examine the JavaScript values. After examining values, you can resume the execution of code using the play button.
**[⬆ Back to Top](#table-of-contents)**
165. ### Can I use reserved words as identifiers
166. ### Can I use reserved words as identifiers
No, you cannot use the reserved words as variables, labels, object or function names. Let's see one simple example,
@@ -3230,7 +3237,7 @@
**[⬆ Back to Top](#table-of-contents)**
166. ### How do you detect a mobile browser
167. ### How do you detect a mobile browser
You can use regex which returns a true or false value depending on whether or not the user is browsing with a mobile.
@@ -3254,7 +3261,7 @@
**[⬆ Back to Top](#table-of-contents)**
167. ### How do you detect a mobile browser without regexp
168. ### How do you detect a mobile browser without regexp
You can detect mobile browsers by simply running through a list of devices and checking if the useragent matches anything. This is an alternative solution for RegExp usage,
@@ -3278,7 +3285,7 @@
**[⬆ Back to Top](#table-of-contents)**
168. ### How do you get the image width and height using JS
169. ### How do you get the image width and height using JS
You can programmatically get the image and check the dimensions(width and height) using Javascript.
@@ -3292,7 +3299,7 @@
**[⬆ Back to Top](#table-of-contents)**
169. ### How do you make synchronous HTTP request
170. ### How do you make synchronous HTTP request
Browsers provide an XMLHttpRequest object which can be used to make synchronous HTTP requests from JavaScript
@@ -3307,7 +3314,7 @@
**[⬆ Back to Top](#table-of-contents)**
170. ### How do you make asynchronous HTTP request
171. ### How do you make asynchronous HTTP request
Browsers provide an XMLHttpRequest object which can be used to make asynchronous HTTP requests from JavaScript by passing the 3rd parameter as true.
@@ -3325,7 +3332,7 @@
**[⬆ Back to Top](#table-of-contents)**
171. ### How do you convert date to another timezone in javascript
172. ### How do you convert date to another timezone in javascript
You can use the toLocaleString() method to convert dates in one timezone to another. For example, let's convert current date to British English timezone as below,
@@ -3335,7 +3342,7 @@
**[⬆ Back to Top](#table-of-contents)**
172. ### What are the properties used to get size of window
173. ### What are the properties used to get size of window
You can use innerWidth, innerHeight, clientWidth, clientHeight properties of windows, document element and document body objects to find the size of a window. Let's use them combination of these properties to calculate the size of a window or document,
@@ -3353,7 +3360,7 @@
**[⬆ Back to Top](#table-of-contents)**
173. ### What is a conditional operator in javascript
174. ### What is a conditional operator in javascript
The conditional (ternary) operator is the only JavaScript operator that takes three operands which acts as a shortcut for if statements.
@@ -3366,7 +3373,7 @@
**[⬆ Back to Top](#table-of-contents)**
174. ### Can you apply chaining on conditional operator
175. ### Can you apply chaining on conditional operator
Yes, you can apply chaining on conditional operators similar to **if … else if … else if … else** chain. The syntax is going to be as below,
@@ -3398,7 +3405,7 @@
**[⬆ Back to Top](#table-of-contents)**
175. ### What are the ways to execute javascript after page load
176. ### What are the ways to execute javascript after page load
You can execute javascript after page load in many different ways,
@@ -3422,7 +3429,7 @@

**[⬆ Back to Top](#table-of-contents)**

176. ### What is the difference between proto and prototype
177. ### What is the difference between proto and prototype

The `__proto__` object is the actual object that is used in the lookup chain to resolve methods, etc. Whereas `prototype` is the object that is used to build `__proto__` when you create an object with new.

@@ -3442,7 +3449,7 @@

**[⬆ Back to Top](#table-of-contents)**

177. ### Can you give an example of when you really need a semicolon
178. ### Can you give an example of when you really need a semicolon

It is recommended to use semicolons after every statement in JavaScript. For example, in the below case it throws an error ".. is not a function" at runtime due to missing semicolon.

@@ -3474,7 +3481,7 @@

**[⬆ Back to Top](#table-of-contents)**

178. ### What is a freeze method
179. ### What is a freeze method

The **freeze()** method is used to freeze an object. Freezing an object does not allow adding new properties to an object, prevents removing, and prevents changing the enumerability, configurability, or writability of existing properties. i.e. It returns the passed object and does not create a frozen copy.

@@ -3508,7 +3515,7 @@
**[⬆ Back to Top](#table-of-contents)**
179. ### What is the purpose of freeze method
180. ### What is the purpose of freeze method
Below are the main benefits of using freeze method,
@@ -3517,13 +3524,13 @@
**[⬆ Back to Top](#table-of-contents)**
180. ### Why do I need to use freeze method
181. ### Why do I need to use freeze method
In the Object-oriented paradigm, an existing API contains certain elements that are not intended to be extended, modified, or re-used outside of their current context. Hence it works as the `final` keyword which is used in various languages.
**[⬆ Back to Top](#table-of-contents)**
181. ### How do you detect a browser language preference
182. ### How do you detect a browser language preference
You can use navigator object to detect a browser language preference as below,
@@ -3538,7 +3545,7 @@
**[⬆ Back to Top](#table-of-contents)**
182. ### How to convert string to title case with javascript
183. ### How to convert string to title case with javascript
Title case means that the first letter of each word is capitalized. You can convert a string to title case using the below function,
@@ -3553,7 +3560,7 @@
**[⬆ Back to Top](#table-of-contents)**
183. ### How do you detect javascript disabled in the page
184. ### How do you detect javascript disabled in the page
You can use the `<noscript>` tag to detect javascript disabled or not. The code block inside `<noscript>` gets executed when JavaScript is disabled, and is typically used to display alternative content when the page generated in JavaScript.
@@ -3568,7 +3575,7 @@
**[⬆ Back to Top](#table-of-contents)**
184. ### What are various operators supported by javascript
185. ### What are various operators supported by javascript
An operator is capable of manipulating(mathematical and logical computations) a certain value or operand. There are various operators supported by JavaScript as below,
@@ -3581,7 +3588,7 @@
**[⬆ Back to Top](#table-of-contents)**
185. ### What is a rest parameter
186. ### What is a rest parameter
Rest parameter is an improved way to handle function parameters which allows us to represent an indefinite number of arguments as an array. The syntax would be as below,