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
+61-1Lines changed: 61 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -35,7 +35,11 @@ Top JavaScript interview questions
35
35
| 27 |[What is the difference between a parameter and an argument](#27-what-is-the-difference-between-a-parameter-and-an-argument)|
36
36
| 28 |[What is a closure](#28-what-is-a-closure)|
37
37
| 29 |[Difference between function declaration and function expression](#29-difference-between-function-declaration-and-function-expression)|
38
-
38
+
| 30 |[What are the different ways to create an array in javascript](#30-what-are-the-different-ways-to-create-an-array-in-javascript)|
39
+
| 31 |[Difference between window and document in javascript](#31-difference-between-window-and-document-in-javascript)|
40
+
| 32 |[What is strict mode in javaScript](#32-what-is-strict-mode-in-javascript)|
41
+
| 33 |[What are the different ways to empty an array in javascript](#33-what-are-the-different-ways-to-empty-an-array-in-javascript)|
42
+
| 34 |[What is NaN in javascript](#34-what-is-nan-in-javascript)|
39
43
40
44
### 1. What is JavaScript
41
45
* JavaScript is a scripting language used to create dynamic and interactive websites. It is supported by all major web browsers.
@@ -445,6 +449,62 @@ const Message = function() {
445
449
Message();
446
450
```
447
451
452
+
### 30. What are the different ways to create an array in javascript
453
+
1. **Using the array literal notation**
454
+
```js
455
+
constarr= [1,2,3,4,5];
456
+
```
457
+
2. **Using the Array() constructor**
458
+
```js
459
+
constarr=newArray(1, 2, 3, 4, 5);
460
+
```
461
+
462
+
### 31. Difference between window and document in javascript
463
+
**window object** - window is the topmost object. It represents the browser window or tab containing a DOM document. It provides various properties and methods to manipulate the browser window, such as window.alert(), window.confirm(), and window.location.
464
+
465
+
**document object** - document represents the HTML document that is being displayed in the window. It provides properties and methods to manipulate the HTML elements in the document, such as document.title, document.getElementById(), and document.createElement().
466
+
467
+
### 32. What is strict mode in JavaScript
468
+
1. Strict mode was introduced in ECMAScript 5
469
+
2. It performs additional checks on your code to prevent certain types of bugs and errors that may go unnoticed e.g., using undeclared variables, using duplicate property names in objects
470
+
3. It can be enabled at either the global level or at the function level
471
+
4. It can't be apply to block statements enclosed in {} braces
472
+
5. To invoke strict mode, put the exact statement “use strict”; or ‘use strict’;
473
+
474
+
### 33. What are the different ways to empty an array in javaScript
475
+
**Using length property**
476
+
```js
477
+
let arr = [1, 2, 3, 4, 5];
478
+
arr.length=0;
479
+
console.log(arr); // output ========> []
480
+
```
481
+
482
+
**Assigning it to a new empty array**
483
+
```js
484
+
let arr = [1,2,3,4,5];
485
+
arr = [];
486
+
console.log(arr); // output ========> []
487
+
```
488
+
489
+
**Using the splice() method**
490
+
```js
491
+
let arr = [1, 2, 3, 4, 5];
492
+
arr.splice(0, arr.length);
493
+
console.log(arr); // output ========> []
494
+
```
495
+
496
+
### 34. What is NaN in javascript
497
+
1. In Javascript, NaN stands for "Not a Number"
498
+
2. It is a global property that represents an unrepresentable mathematical result
499
+
3. It is returned when a mathematical operation has no meaningful result. E.g., dividing zero by zero, multiplying/dividing a non-numeric value by a number etc.
500
+
501
+
```js
502
+
console.log(0/0); // output ========> NaN
503
+
console.log("a"*1); // output ========> NaN
504
+
console.log("a"/1) // output ========> NaN
505
+
console.log(Math.sqrt(-1)); // output ========> NaN
506
+
console.log(parseInt("blabla")); // output ========> NaN
0 commit comments