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 32d4e8f

Browse files
committed
new questions added
1 parent d19adac commit 32d4e8f

File tree

1 file changed

+96
-1
lines changed

1 file changed

+96
-1
lines changed

β€ŽREADME.md

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

@@ -295,3 +295,98 @@ _It makes difference when position of `x++` code changes wrt the setTimout callb
295295
So all the 5 `callbacks` logs the values in `incremental` way, which is `1 2 3 4 5`.
296296

297297
</details>
298+
299+
<details>
300+
<summary>
301+
<h3>11. Guess the output of this JavaScript code?
302+
303+
```js
304+
let a = { x: 1 };
305+
let b = { x: 2 };
306+
let c = { x: 3 };
307+
let d = { x: 4 };
308+
let e = { x: 5 };
309+
let arr = [a, b, c, d, e];
310+
311+
arr.forEach((obj) => (obj.x = obj.x * 2));
312+
313+
console.log(a.x, b.x, c.x, d.x, e.x);
314+
```
315+
316+
</h3>
317+
</summary>
318+
Answer:
319+
320+
2 4 6 8 10
321+
322+
The code is using the `forEach` method to iterate over an array of objects, and it is modifying the `x` property of each object by multiplying it by 2.
323+
324+
It's updating the original objects with `x*2` values.
325+
326+
So, the output of the code is 2 4 6 8 10.
327+
328+
</details>
329+
330+
<details>
331+
<summary>
332+
<h3>12. Guess the output of the JavaScript code?
333+
334+
```js
335+
let num = 0;
336+
337+
function test() {
338+
var num = 1;
339+
return num;
340+
}
341+
342+
console.log(test());
343+
console.log(num);
344+
```
345+
346+
</h3>
347+
</summary>
348+
Answer:
349+
1
350+
0
351+
352+
The code defines a global variable num with the value of 0 and then a function test which declares a local variable num with the value of 1 and returns it.
353+
354+
When test() is called, it first declares a local variable num with the value of 1.
355+
356+
Then the function return statement logs 1 on the console.
357+
358+
After that, it logs the value of global variable num which is 0.
359+
360+
Because the global and local variables have different scope and different memory allocation.
361+
362+
</details>
363+
364+
<details>
365+
<summary>
366+
<h3>13. Guess the output of the below JavaScript code?
367+
368+
```js
369+
let obj = { name: "John", age: 25 };
370+
let newObj = { ...obj, age: 30 };
371+
372+
console.log(obj.age);
373+
console.log(newObj.age);
374+
```
375+
376+
</h3>
377+
</summary>
378+
Answer:
379+
25
380+
30
381+
382+
The code creates an object obj with properties name and age. Then it creates a new object newObj using the spread operator to copy the properties of obj and then it updates the age property to 30.
383+
384+
The spread operator `...` creates a new object with properties copied from the original object.
385+
386+
So, the first console.log statement logs the value of age property of obj which is `25`.
387+
388+
And, the second console.log statement logs the value of age property of newObj which is `30`.
389+
390+
It doesn't affect the original object `obj`.
391+
392+
</details>

0 commit comments

Comments
(0)

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