Skip to content

Commit 4b1f772

Browse files
authored
Question-Answers 30-34
1 parent 7b951bb commit 4b1f772

File tree

1 file changed

+61
-1
lines changed

1 file changed

+61
-1
lines changed

README.md

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@ Top JavaScript interview questions
3535
| 27 | [What is the difference between a parameter and an argument](#27-what-is-the-difference-between-a-parameter-and-an-argument) |
3636
| 28 | [What is a closure](#28-what-is-a-closure) |
3737
| 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) |
3943

4044
### 1. What is JavaScript
4145
* 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() {
445449
Message();
446450
```
447451
452+
### 30. What are the different ways to create an array in javascript
453+
1. **Using the array literal notation**
454+
```js
455+
const arr = [1,2,3,4,5];
456+
```
457+
2. **Using the Array() constructor**
458+
```js
459+
const arr = new Array(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
507+
```
448508
******************************In progress
449509
450510

0 commit comments

Comments
 (0)