Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e6b344a

Browse files
committed
New JS Question added
1 parent 481c5b7 commit e6b344a

File tree

1 file changed

+132
-1
lines changed

1 file changed

+132
-1
lines changed

β€ŽREADME.mdβ€Ž

Lines changed: 132 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: "Prepare for your next 2023 JavaScript interview with these tricky
44
githubPath: "https://github.com/Vasu7389/JavaScript-Interview-Questions-2023"
55
---
66

7-
<span style=" font-size: 1rem; border-bottom: 1px solid grey;"> Updated June 22, 2023 </span>
7+
<span style=" font-size: 1rem; border-bottom: 1px solid grey;"> Updated July 19, 2023 </span>
88

99
In this article, we will cover a range of JavaScript interview questions, including those related to the latest versions of the language (ES6, ES7, ES8, and ES9).
1010

@@ -1316,3 +1316,134 @@ Since `x` is accessible within the `bar` function due to lexical scoping, the va
13161316
Hence, the correct answer is C: 3.
13171317
13181318
</details>
1319+
1320+
<details>
1321+
<summary>
1322+
<h3>41. What will be the output of the following code snippet?</h3>
1323+
1324+
```javascript
1325+
let x = 10;
1326+
1327+
function outer() {
1328+
console.log(x);
1329+
1330+
if (false) {
1331+
var x = 20;
1332+
}
1333+
}
1334+
1335+
outer();
1336+
```
1337+
1338+
- A: 10
1339+
- B: 20
1340+
- C: undefined
1341+
- D: ReferenceError
1342+
1343+
</summary>
1344+
1345+
Answer:
1346+
C: undefined
1347+
1348+
In this code snippet, there's a variable hoisting issue with the var declaration inside the outer function. The variable x is declared using var within the outer function scope.
1349+
1350+
When the function outer() is called, the console.log(x) statement is executed. At this point, the variable x is hoisted to the top of the function scope and is initialized with undefined. This means that the local variable x inside the function is different from the global x.
1351+
1352+
The if (false) block will not be executed, so the assignment var x = 20; will not take place.
1353+
1354+
Thus, the console.log(x) statement inside the outer function will log the value of the locally hoisted variable x, which is undefined.
1355+
1356+
Hence, the correct answer is C: undefined.
1357+
1358+
</details>
1359+
1360+
<details>
1361+
<summary>
1362+
<h3>42. What will be the output of the following code snippet?</h3>
1363+
1364+
```javascript
1365+
const obj = {
1366+
a: 1,
1367+
b: 2,
1368+
c: {
1369+
a: 3,
1370+
b: 4,
1371+
},
1372+
};
1373+
1374+
const {
1375+
a,
1376+
b,
1377+
c: { a: nestedA },
1378+
} = obj;
1379+
1380+
console.log(a, b, nestedA);
1381+
```
1382+
1383+
- A: 1 2 3
1384+
- B: 1 2 4
1385+
- C: 3 2 1
1386+
- D: SyntaxError
1387+
1388+
</summary>
1389+
1390+
Answer:
1391+
A: 1 2 3
1392+
1393+
This code snippet uses destructuring assignment to extract values from the `obj` object. It extracts the properties `a`, `b`, and the nested property `a` from the `c` object and assigns them to the corresponding variables `a`, `b`, and `nestedA`, respectively.
1394+
1395+
After destructuring, the variables will hold the following values:
1396+
1397+
- `a`: 1 (value of `obj.a`)
1398+
- `b`: 2 (value of `obj.b`)
1399+
- `nestedA`: 3 (value of `obj.c.a`)
1400+
1401+
When `console.log(a, b, nestedA)` is executed, it will print `1 2 3`, as the values of the variables match the above assignments.
1402+
1403+
Hence, the correct answer is A: 1 2 3.
1404+
1405+
</details>
1406+
1407+
<details>
1408+
<summary>
1409+
<h3>43. What will be the output of the following code snippet?</h3>
1410+
1411+
```javascript
1412+
function* generatorFunction() {
1413+
yield 1;
1414+
yield 2;
1415+
return 3;
1416+
}
1417+
1418+
const generator = generatorFunction();
1419+
1420+
console.log(generator.next());
1421+
console.log(generator.next());
1422+
console.log(generator.next());
1423+
```
1424+
1425+
- A: { value: 1, done: false }, { value: 2, done: false }, { value: 3, done: true }
1426+
- B: { value: 1, done: false }, { value: 2, done: false }, { value: undefined, done: true }
1427+
- C: { value: 1, done: true }, { value: 2, done: true }, { value: 3, done: true }
1428+
- D: SyntaxError
1429+
1430+
</summary>
1431+
1432+
Answer:
1433+
A: { value: 1, done: false }, { value: 2, done: false }, { value: 3, done: true }
1434+
1435+
This code snippet demonstrates the use of a generator function. When a generator function is called, it returns an iterator object, which can be used to control the execution of the generator function.
1436+
1437+
The `generatorFunction` is a generator function that yields three values: `1`, `2`, and `3`. The `yield` keyword pauses the execution and returns the yielded value. When the generator is finished, it returns the value using the `return` statement.
1438+
1439+
When the generator is executed step by step using `generator.next()`, it proceeds through the generator function's code, stopping at each `yield` statement.
1440+
1441+
- The first call to `generator.next()` will return `{ value: 1, done: false }`, indicating that the first value yielded is `1`, and the generator is not yet done.
1442+
- The second call to `generator.next()` will return `{ value: 2, done: false }`, indicating that the second value yielded is `2`, and the generator is not yet done.
1443+
- The third call to `generator.next()` will return `{ value: 3, done: true }`, indicating that the third value yielded is `3`, and the generator is done (`done` is `true`).
1444+
1445+
After the generator is done, any further calls to `generator.next()` will keep returning `{ value: undefined, done: true }`.
1446+
1447+
Hence, the correct answer is A: { value: 1, done: false }, { value: 2, done: false }, { value: 3, done: true }.
1448+
1449+
</details>

0 commit comments

Comments
(0)

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /