You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+150-3Lines changed: 150 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -27,6 +27,15 @@ Top JavaScript interview questions
27
27
| 19 |[What is a callback function](#19-what-is-a-callback-function)|
28
28
| 20 |[Is it possible to have both local and global variables with the same name](#20-is-it-possible-to-have-both-local-and-global-variables-with-the-same-name)|
29
29
| 21 |[Difference between Local Storage and Session Storage](#21-difference-between-local-storage-and-session-storage)|
30
+
| 22 |[Difference between forEach() and map()](#22-difference-between-foreach-and-map)|
31
+
| 23 |[What is rest operator](#23-what-is-rest-operator)|
32
+
| 24 |[What is spread operator](#24-what-is-spread-operator)|
33
+
| 25 |[Difference between async and defer](#25-difference-between-async-and-defer)|
34
+
| 26 |[What is Nullish coalescing operator](#26-what-is-nullish-coalescing-operator)|
35
+
| 27 |[What is the difference between a parameter and an argument](#27-what-is-the-difference-between-a-parameter-and-an-argument)|
36
+
| 28 |[What is a closure](#28-what-is-a-closure)|
37
+
| 29 |[Difference between function declaration and function expression](#29-difference-between-function-declaration-and-function-expression)|
38
+
30
39
31
40
### 1. What is JavaScript
32
41
* JavaScript is a scripting language used to create dynamic and interactive websites. It is supported by all major web browsers.
### 4. Difference between "==" and "===" operators
86
95
* == : While comparing two operands, checks for only value
96
+
```js
97
+
console.log(1=="1"); // output=>>>>>>>>> true
98
+
```
87
99
* === : While comparing two operands, checks for value as well as data type
100
+
```js
101
+
console.log(1==="1"); // output=>>>>>>>>> false
102
+
```
88
103
89
104
### 5. Is javascript single-threaded or multi-threaded
90
105
* JavaScript is Single-threaded
@@ -200,7 +215,7 @@ The output of above code will be 10 because the variable "a" is hoisted to the t
200
215
```javascript
201
216
demo(); // demo console
202
217
functiondemo() {
203
-
console.log('demo console'); //
218
+
console.log('demo console');
204
219
}
205
220
```
206
221
The output of above code will be "demo console" because the function declaration is hoisted to the top of the scope, allowing it to be called before it is declared in the code.
@@ -247,8 +262,8 @@ function memoizedAdd(num1, num2) {
247
262
}
248
263
249
264
constadd=memoizedAdd();
250
-
console.log(add(2, 3)); // "Calculating result:", "2 and 3", output=====> 5
251
-
console.log(add(2, 3)); // "Retrieving from cache:", "2 and 3" output=====> 5
console.log(add(2, 3)); // "Retrieving from cache:", "2 and 3" output ========> 5
252
267
```
253
268
254
269
### 18. Difference between var, let and const
@@ -298,6 +313,138 @@ Local storage and session storage are web storage provided by web browsers to st
298
313
299
314
**Session Storage** - Data stored in session storage will be deleted when the browser window is closed or the session ends and it is available only within the same window or tab that created the data.
300
315
316
+
### 22. Difference between forEach() and map()
317
+
map() and forEach() are array methods that can be used to iterate over an array.
318
+
**map()**
319
+
1. map() method receives a function as an argument, executes it once for each array element and returns a new array
320
+
2. It is generally used when we need to modify/change data, because it returns a new array with the transformed data
321
+
3. It is chainable because we can attach sort(), filter() etc. after performing a map() method on an array
async and defer are the attributes used with the script tag in HTML to load javaScript files.
384
+
385
+
**Async** - The script is loaded in parallel to the HTML parsing, and executed as soon as it is available i.e., it executes the script immediately after it is loaded. It can be useful for scripts that don't depend on the DOM.
386
+
387
+
**Defer** - The script is loaded in parallel to the HTML parsing, and executed after the page is completely loaded i.e., it waits until the page has finished parsing. It can be useful for scripts that depend on the DOM.
388
+
389
+
### 26. What is Nullish coalescing operator
390
+
1. The nullish coalescing (??) operator is a logical operator
391
+
2. It allows you to check if a value is either null or undefined
392
+
3. It returns its right-hand side operand if its left-hand side operand is null or undefined, otherwise returns its left-hand side operand
### 27. What is the difference between a parameter and an argument
399
+
**Parameter** - A parameter is a variable that is defined during a function declaration or definition. It represents a value that the function or method expects to receive as an input.
400
+
401
+
**Argument** - An argument is the actual value that is passed to a function or method when it is called.
402
+
```js
403
+
functionDemo(parameter1, parameter2){
404
+
something------
405
+
something------
406
+
}
407
+
Demo(argument1, argument2);
408
+
```
409
+
410
+
### 28. What is a closure
411
+
A closure is a combination of a function and the environment in which it was created(lexical scope). It gives you access to an outer function's scope from an inner function even if the outer function has returned
412
+
```js
413
+
functionDemo() {
414
+
let name ="Surbhi";
415
+
functiondisplayName() {
416
+
console.log(name);
417
+
}
418
+
return displayName;
419
+
}
420
+
421
+
constresult=Demo();
422
+
result();
423
+
```
424
+
425
+
### 29. Difference between function declaration and function expression
426
+
**Function Declaration**
427
+
1. A function declaration defines a function using the function keyword, followed by the function name
428
+
2. We can call a function, declared using a function declaration, before it is defined. Because it is hoisted to the top of its scope
0 commit comments