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 eb58231

Browse files
committed
new questions added
1 parent 77ed5c8 commit eb58231

File tree

1 file changed

+102
-1
lines changed

1 file changed

+102
-1
lines changed

β€ŽREADME.mdβ€Ž

Lines changed: 102 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: 0.8rem; border-bottom: 1px solid grey;"> Updated Jan 19, 2023 </span>
7+
<span style=" font-size: 0.8rem; border-bottom: 1px solid grey;"> Updated Feb 10, 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

@@ -390,3 +390,104 @@ And, the second console.log statement logs the value of age property of newObj w
390390
It doesn't affect the original object `obj`.
391391

392392
</details>
393+
394+
<details>
395+
<summary>
396+
<h3>14. Guess the output of the below JavaScript code?
397+
398+
```js
399+
const add = (a = 1, b = 2) => a + b;
400+
console.log(add());
401+
console.log(add(5));
402+
console.log(add(undefined, 10));
403+
```
404+
405+
</h3>
406+
</summary>
407+
408+
Answer:
409+
410+
```bash
411+
3
412+
7
413+
11
414+
```
415+
416+
The code defines a function add which takes two parameters a and b and returns the sum of both. It uses default parameters to assign default values 1 to a and 2 to b if they are not provided.
417+
418+
So, the first console.log statement logs the result of add() which is 1 + 2 = 3 as both the parameters are not provided and default values are used.
419+
420+
The second console.log statement logs the result of add(5) which is 5 + 2 = 7 as only the first parameter is provided and the default value of b is used.
421+
422+
The third console.log statement logs the result of add(undefined, 10) which is 1 + 10 = 11 as the first parameter is provided as undefined and it takes the default value 1 and the second parameter is provided as 10.
423+
424+
</details>
425+
426+
<details>
427+
<summary>
428+
<h3>15. Guess the output of the below JavaScript code?
429+
430+
```js
431+
const name = "John";
432+
const age = 25;
433+
434+
const user = { name, age };
435+
console.log(user);
436+
```
437+
438+
</h3>
439+
</summary>
440+
441+
Answer:
442+
443+
```js
444+
{ name: "John", age: 25 }
445+
```
446+
447+
The code defines two variables name and age with values "John" and 25 respectively.
448+
449+
Then, it uses `object literal` notation to create an object user with properties `name` and `age` and the values are assigned from the variables name and age respectively.
450+
451+
So, the `console.log` statement logs the user object which is `{ name: "John", age: 25 }`.
452+
453+
In `ES6+`, you can use object literal notation to create objects with properties using the same name as the variables with the values assigned to them.
454+
455+
</details>
456+
457+
<details>
458+
<summary>
459+
<h3>16. Guess the output of the below JavaScript code?
460+
461+
```js
462+
const arr = [1, 2, 3];
463+
const [a, b, c] = arr;
464+
465+
console.log(a);
466+
console.log(b);
467+
console.log(c);
468+
```
469+
470+
</h3>
471+
</summary>
472+
473+
Answer:
474+
475+
```bash
476+
1
477+
2
478+
3
479+
```
480+
481+
The code defines an array arr with values [1, 2, 3].
482+
483+
Then, it uses `destructuring assignment` to extract the values from the array `arr` and assign them to variables `a`, `b`, and `c` respectively.
484+
485+
So, the first console.log statement logs the value of a which is `1`.
486+
487+
The second console.log statement logs the value of b which is `2`.
488+
489+
The third console.log statement logs the value of c which is `3`.
490+
491+
In ES6+, you can use destructuring assignment to extract values from arrays and objects and assign them to variables in a concise way.
492+
493+
</details>

0 commit comments

Comments
(0)

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