From eb2360e50f6f1db6c6e3355f3e18910ca647e635 Mon Sep 17 00:00:00 2001 From: Sankalp Pareek Date: Sat, 24 May 2025 20:37:59 +0530 Subject: [PATCH 1/2] added questions based on function modification, object shallow copies, hoisting behaviour and event loop execution --- README.md | 130 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) diff --git a/README.md b/README.md index 96a2564..3a17c01 100644 --- a/README.md +++ b/README.md @@ -712,3 +712,133 @@ console.log(Object.keys(arr)); **[:top: Scroll to Top](#javascript-output-based-interview-questions)** +**41. What will be the output** +```js +function modify(obj) { + obj.name = "Updated"; +} + +let person = { name: "Original" }; +modify(person); +console.log(person.name); + +function reassign(obj) { + obj = { name: "New Object" }; +} + +reassign(person); +console.log(person.name); +``` +
+ View Answer + +
+ +**[:top: Scroll to Top](#javascript-output-based-interview-questions)** + + +**42. What will be the output** +```js +let a={ x:1, y: {alpha:10,beta:20} }; +let b = {...a}; +b.x=101; +b.y.alpha=1001; +console.log(a.x); +console.log(a.y.alpha); +``` +
+ View Answer + +
+ +**[:top: Scroll to Top](#javascript-output-based-interview-questions)** + + +**43. What will be the output** +```js +greet(); +function greet() { + console.log("Hello"); +} +``` +
+ View Answer + +
+ +**[:top: Scroll to Top](#javascript-output-based-interview-questions)** + + + +**44. What will be the output** +```js +greet(); +var greet = function() { + console.log("Hi"); +} +``` +
+ View Answer + +
+ +**[:top: Scroll to Top](#javascript-output-based-interview-questions)** + +**45. What will be the output** +```js +console.log('Start'); + +setTimeout(() => { + console.log('setTimeout'); +}, 0); + +Promise.resolve().then(() => { + console.log('Promise'); +}); + +console.log('End'); +``` + +**45. What will be the output** +```js +console.log('Start'); + +setTimeout(() => { + console.log('setTimeout'); +}, 0); + +Promise.resolve().then(() => { + console.log('Promise'); +}); + +console.log('End'); +``` +
+ View Answer + +
+ +**[:top: Scroll to Top](#javascript-output-based-interview-questions)** \ No newline at end of file From 14aaad8a166070139c53af5391cf32608466e322 Mon Sep 17 00:00:00 2001 From: Sankalp Pareek Date: Wed, 28 May 2025 22:16:46 +0530 Subject: [PATCH 2/2] removing redundant/logically duplicate questions --- README.md | 38 +------------------------------------- 1 file changed, 1 insertion(+), 37 deletions(-) diff --git a/README.md b/README.md index 3a17c01..f0df4a6 100644 --- a/README.md +++ b/README.md @@ -762,42 +762,6 @@ console.log(a.y.alpha); **43. What will be the output** ```js -greet(); -function greet() { - console.log("Hello"); -} -``` -
- View Answer -
    -
  • Output : The console will output `"Hello"`.
  • -
  • Reason : Function declarations are hoisted, meaning the `greet` function is fully available before it's called. So when `greet();` is executed, it successfully prints `"Hello"` to the console.
  • -
-
- -**[:top: Scroll to Top](#javascript-output-based-interview-questions)** - - - -**44. What will be the output** -```js -greet(); -var greet = function() { - console.log("Hi"); -} -``` -
- View Answer -
    -
  • Output : The code will throw a TypeError.
  • -
  • Reason : While `var greet` is hoisted, it is initialized with undefined at the time of execution. Therefore, calling greet(); before the assignment results in an error becuase undefined is not a function.
  • -
-
- -**[:top: Scroll to Top](#javascript-output-based-interview-questions)** - -**45. What will be the output** -```js console.log('Start'); setTimeout(() => { @@ -811,7 +775,7 @@ Promise.resolve().then(() => { console.log('End'); ``` -**45. What will be the output** +**44. What will be the output** ```js console.log('Start');