Advanced JavaScript Interview Questions
1. Variable Hoisting and Temporal Dead Zone
[Link](a);
let a = 5;
2. Closure Inside a Loop
for (var i = 0; i < 3; i++) {
setTimeout(() => [Link](i), 100);
}
3. Currying and Execution Order
function add(a) {
return function(b) {
return function(c) {
[Link](a + b + c);
};
};
}
add(1)(2)(3);
4. Object Reference and Mutation
let a = { x: 1 };
let b = a;
a.x = 2;
b = { x: 3 };
[Link](a.x);
5. Function Scope vs Block Scope
function test() {
if (true) {
var a = 5;
let b = 10;
}
[Link](a);
[Link](b);
}
test();
6. Implicit `this` Binding
const obj = {
value: 42,
getValue: function () {
return [Link];
}
};
const getValue = [Link];
[Link](getValue());
7. Promise Resolution Order
[Link]().then(() => {
[Link]("Promise 1");
}).then(() => {
[Link]("Promise 2");
});
setTimeout(() => [Link]("Timeout"), 0);
[Link]("Sync");
8. async/await with Error Handling
async function f() {
try {
await [Link]("Error");
} catch (e) {
[Link]("Caught:", e);
}
}
f();
9. `this` in Arrow vs Regular Functions
const obj = {
count: 10,
regular: function () {
setTimeout(function () {
[Link]([Link]);
}, 100);
},
arrow: function () {
setTimeout(() => {
[Link]([Link]);
}, 100);
}
};
[Link]();
[Link]();
10. Deep Freeze Object Mutation
const obj = [Link]({ x: { y: 10 } });
obj.x.y = 20;
[Link](obj.x.y);
11. Prototype Chain Manipulation
function A() {}
[Link] = function () {
return "Hi";
};
const a = new A();
[Link] = {
sayHi: function () {
return "Hello";
}
};
[Link]([Link]());
12. Destructuring and Default Values
const { a, b = 5 } = { a: 3, b: undefined };
[Link](a, b);
13. Symbol Key Properties
const sym = Symbol("secret");
const obj = {
[sym]: "hidden",
normal: "visible"
};
[Link]([Link](obj));
[Link]([Link](obj));
14. Generator Function Flow
function* gen() {
yield 1;
yield 2;
return 3;
}
const g = gen();
[Link]([Link]());
[Link]([Link]());
[Link]([Link]());
15. Proxy Trap Behavior
const target = { a: 1 };
const proxy = new Proxy(target, {
get(target, prop) {
return prop in target ? target[prop] : 42;
}
});
[Link](proxy.a);
[Link](proxy.b);
16. Event Loop Depth
setTimeout(() => [Link]("setTimeout"), 0);
[Link]().then(() => {
[Link]("promise");
});
queueMicrotask(() => {
[Link]("microtask");
});
[Link]("sync");
17. Module Hoisting (ESM)
// Assuming this is an ES module
[Link](x);
import { x } from './[Link]';
18. Type Coercion Madness
[Link]([] + []);
[Link]([] + {});
[Link]({} + []);
19. `[Link]` Behavior
function A() {
if (![Link]) throw "Use new!";
}
A();
20. Class Private Fields
class MyClass {
#secret = 123;
reveal() {
return this.#secret;
}
}
const obj = new MyClass();
[Link]([Link]());
[Link](obj.#secret);
21. Async Constructor Simulation
class Person {
constructor(name) {
[Link] = name;
}
static async create(name) {
return new Promise(resolve => {
setTimeout(() => resolve(new Person(name)), 100);
});
}
}
[Link]("John").then(p => [Link]([Link]));
22. Optional Chaining with Function Calls
const obj = {
fn: () => "hello"
};
[Link]([Link]?.());
[Link]([Link]?.());
23. Map vs Object Key Behavior
const map = new Map();
[Link]({}, "value1");
[Link]({}, "value2");
[Link]([Link]);
24. `[Link]` vs `===`
[Link]([Link](+0, -0));
[Link](+0 === -0);
25. Eval Scope Trap
function test() {
let x = 10;
eval("let x = 20; [Link](x);");
[Link](x);
}
test();