Skip to content

Commit f99d1bd

Browse files
authored
Added Question 94 and 95
1 parent 7ed0eda commit f99d1bd

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ Every contribution counts, regardless of its size. I value and appreciate the ef
110110
| 91 | [Does JavaScript support automatic type conversion](#91-does-javascript-support-automatic-type-conversion) |
111111
| 92 | [What is variable shadowing in javascript](#92-what-is-variable-shadowing-in-javascript) |
112112
| 93 | [What is ternary operator](#93-what-is-ternary-operator) |
113+
| 94 | [Difference between Sparse array and Dense array](#94-difference-between-sparse-array-and-dense-array) |
114+
| 95 | [How does the length property behave in dense vs sparse arrays in JavaScript](#95-how-does-the-length-property-behave-in-dense-vs-sparse-arrays-in-javascript) |
113115

114116
### 1. What is JavaScript
115117
* JavaScript is a scripting language used to create dynamic and interactive websites. It is supported by all major web browsers.
@@ -1368,3 +1370,35 @@ console.log(result); // output ========> output 1
13681370
13691371
**[:top: Scroll to Top](#javascript-interview-questions)**
13701372
1373+
### 94. Difference between Sparse array and Dense array
1374+
**Sparse Array** - An array that has "holes" i.e some indices are unassigned or missing.
1375+
```js
1376+
const sparse = [1, , 3]; // index 1 is empty
1377+
```
1378+
**Dense Array** - An array where every index has an assigned value, with no gaps.
1379+
```js
1380+
const dense = [1, 2, 3];
1381+
```
1382+
1383+
**[:top: Scroll to Top](#javascript-interview-questions)**
1384+
1385+
### 95. How does the length property behave in dense vs sparse arrays in Javascript
1386+
**Sparse Array** - "length" is highest index + 1, even if some spots are empty.
1387+
```js
1388+
const sparse = [1, , 3];
1389+
console.log(sparse.length); // output ========> 3
1390+
1391+
OR
1392+
1393+
const arr = [];
1394+
arr[100] = 5;
1395+
console.log(arr.length); // output ========> 101 (index 100 has the value 5, while indices 0–99 are empty)
1396+
1397+
```
1398+
**Dense Array** - "length" equals the number of elements.
1399+
```js
1400+
const dense = [1, 2, 3];
1401+
console.log(dense.length); // output ========> 3
1402+
```
1403+
1404+
**[:top: Scroll to Top](#javascript-interview-questions)**

0 commit comments

Comments
 (0)