0% found this document useful (0 votes)
3 views22 pages

Javascript Docs

The document outlines key concepts and advanced topics in JavaScript, including execution context, data types, functions, asynchronous programming, and object-oriented programming. It also covers important operators, APIs, and common pitfalls such as hoisting and scope issues. Additionally, it provides examples and explanations for various JavaScript behaviors and features, making it a comprehensive resource for mastering the language.

Uploaded by

vamshik2004.ece
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views22 pages

Javascript Docs

The document outlines key concepts and advanced topics in JavaScript, including execution context, data types, functions, asynchronous programming, and object-oriented programming. It also covers important operators, APIs, and common pitfalls such as hoisting and scope issues. Additionally, it provides examples and explanations for various JavaScript behaviors and features, making it a comprehensive resource for mastering the language.

Uploaded by

vamshik2004.ece
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

⚙️ 1.

Core Execution & Fundamentals

 What is JavaScript? How is it different from other languages?

 What is execution context?

 How does the call stack work?

 What is hoisting?

 What is Temporal Dead Zone?

 Difference between var, let, const

 What is scope? (global, function, block)

⚡ 2. Data Types & Coercion

 Primitive vs non-primitive data types

 Pass by value vs pass by reference

 What is typeof null bug?

 Difference between == and ===

 Type coercion rules in JS

 Truthy and falsy values

🧠 3. Functions & Closures

 What are functions in JS?

 What is a callback function?

 What is a higher-order function?

 What is closure? (with use cases)

 What is IIFE?

 Arrow function vs normal function

 What is currying?

 What is memoization?

 What is debouncing and throttling?


🔄 4. Async JavaScript (CRITICAL)

 Synchronous vs asynchronous JS

 What is event loop?

 Microtask vs macrotask queue

 What are Web APIs?

 What is a Promise?

 Promise states and lifecycle

 Promise chaining

 Difference: [Link], race, any, allSettled

 Async/await (how it works internally)

 Error handling in async (try/catch, .catch)

 What is callback hell? How to avoid it?

🎯 5. Objects & Arrays

 Different ways to create objects

 String methods

 What are object methods?

 What is destructuring?

 Spread vs rest operator

 Difference between shallow copy and deep copy

 Array methods: map, filter, reduce, find, forEach

 Difference between map and forEach

🧠 6. this Keyword

 What is this in JS?

 this in global, function, object, arrow function

 Difference between bind, call, apply


🏗 7. Prototypes & OOP

 What is prototype in JS?

 __proto__ vs prototype

 Prototypal inheritance

 Constructor functions

 Classes in JavaScript

🌐 8. DOM & Browser

 What is DOM?

 DOM manipulation methods

 Event bubbling vs capturing

 Event delegation

💾 9. Storage & Browser APIs

 Difference: localStorage, sessionStorage, cookies

⚙️ 10. Advanced Concepts

 What is immutability?

 What is strict mode?

 What is code splitting?

 What are modules? (CommonJS vs ES Modules)

 Basic idea of garbage collection

 Design patterns in JavaScript

🧠 11. Special Operators & APIs

 What is Nullish Coalescing Operator (??)?

 Optional chaining (?.)


 [Link]() vs [Link]()

 Difference between Map and Set

🔥 MISSING IMPORTANT QUESTIONS

⚡ Advanced JavaScript Core

 What is event delegation vs event propagation difference (deep)

 What is [Link]() vs stopPropagation()

 What is [Link] vs [Link]

⚡ Execution & Engine (deeper than basics)

 What is lexical environment

 What is variable environment

 Difference between stack vs heap memory

 What is garbage collection (mark & sweep)

⚡ Functions (advanced)

 What are pure functions

 What are impure functions

 What is function composition

 What is generator function (function*)

⚡ Objects (advanced)

 What is [Link] vs [Link] vs [Link]

 What is property descriptors

 What is [Link]()

⚡ Arrays & Iteration


 Difference between:

o for...in vs for...of

 What are iterators & iterable protocol

⚡ Async Deep Questions (important)

 What is [Link] vs [Link]

 What is finally() in promises

 What is parallel vs sequential async execution

 How to run multiple async calls efficiently

⚡ ES6+ Features (frequently asked)

 What are template literals

 What is optional chaining (?.)

 What is nullish coalescing (??)

 What is default parameters

⚡ Memory & Performance

 What are memory leaks in JS

 How to optimize performance in JS

 What is debounce vs throttle (real implementation use)

⚡ Map / Set Advanced

 Difference between:

o Map vs Object (deep)

o Set vs Array

⚡ Browser & Advanced APIs

 What is MutationObserver
 What is IntersectionObserver

 What is Web Storage vs IndexedDB

⚡ Node / Runtime (if backend asked)

 What is [Link] event loop difference from browser

 What is [Link] vs setImmediate

💣 12. Output-Based / Tricky Questions

 Closures in loops

 Promise execution order

 this behavior confusion

 Hoisting edge cases

 Async execution order

🔥 1. HOISTING

[Link](a);
var a = 5;

✅ Output

undefined

🧠 Why

 JS hoists declaration, not assignment

 Internally becomes:
var a;
[Link](a); // undefined
a = 5;

🔥 2. SCOPE (var vs let)

function test() {
if (true) {
var a = 10;
let b = 20;
}
[Link](a);
[Link](b);
}
test();

✅ Output

10
ReferenceError

🧠 Why

 var → function scoped → accessible

 let → block scoped → not accessible outside {}

🔥 3. TYPE COERCION

[Link]([] + []);
[Link]([] + {});
[Link]({} + []);

✅ Output

""
"[object Object]"
0

🧠 Why

 [] + [] → "" + "" → ""

 [] + {} → "" + "[object Object]"


 {} + [] → treated as block → +[] → 0

🔥 4. CLOSURE

function outer() {
let count = 0;
return function () {
count++;
return count;
};
}

const fn = outer();
[Link](fn());
[Link](fn());

✅ Output

1
2

🧠 Why

 Inner function remembers count

 Same memory reused → increments

🔥 5. ASYNC (Event Loop)

[Link]("A");

setTimeout(() => [Link]("B"), 0);

[Link]().then(() => [Link]("C"));

[Link]("D");

✅ Output

A
D
C
B
🧠 Why

 Sync → A, D

 Microtask (Promise) → C

 Macrotask (setTimeout) → B

🔥 6. this TRAP

const obj = {
name: "JS",
show: function() {
[Link]([Link]);
}
};

const fn = [Link];
fn();

✅ Output

undefined (or [Link] in browser)

🧠 Why

 this depends on caller

 Here → global context, not obj

🔥 7. PROTOTYPE

function Person(name) {
[Link] = name;
}

[Link] = function() {
return [Link];
};

const p = new Person("A");


[Link]([Link]());

✅ Output
A

🧠 Why

 Method stored in prototype

 Instance accesses via prototype chain

🔥 8. REMOVE DUPLICATES

const arr = [1,2,2,3];


const res = [...new Set(arr)];
[Link](res);

✅ Output

[1,2,3]

🧠 Why

 Set stores unique values only

🔥 9. FLATTEN ARRAY

const arr = [1,[2,[3]]];


[Link]([Link](Infinity));

✅ Output

[1,2,3]

🧠 Why

 flat(Infinity) recursively flattens

🔥 10. LOCAL STORAGE

[Link]("user", [Link]({name:"A"}));
const data = [Link]([Link]("user"));
[Link]([Link]);

✅ Output

🧠 Why
 Storage only accepts string → use JSON

🔥 11. DEBOUNCE

function debounce(fn, delay) {


let timer;
return function() {
clearTimeout(timer);
timer = setTimeout(() => fn(), delay);
};
}

🧠 Why

 Clears previous call → only last executes

🔥 12. MEMOIZATION

function memo(fn) {
const cache = {};
return function(n) {
if (cache[n]) return cache[n];
return cache[n] = fn(n);
};
}

🧠 Why

 Stores previous results → avoids recomputation

🔥 13. PROMISE ORDER

[Link]("start");

setTimeout(() => [Link]("timeout"), 0);

[Link]().then(() => [Link]("promise"));

[Link]("end");

✅ Output
start
end
promise
timeout

🔥 14. OBJECT FREEZE

const obj = [Link]({a:1});


obj.a = 2;
[Link](obj.a);

✅ Output

🧠 Why

 Freeze → no modification allowed

🔥 15. MAP vs FOREACH

const arr = [1,2,3];

const a = [Link](x => x*2);


const b = [Link](x => x*2);

[Link](a);
[Link](b);

✅ Output

[2,4,6]
undefined

🧠 Why

 map returns new array

 forEach returns nothing


🔥 QUICK OUTPUT ROUND

⚡1

[Link](1 + "2");

👉 Output: "12"
👉 Why: number + string → string conversion

⚡2

[Link]("5" - 2);

👉 Output: 3
👉 Why: - forces number conversion

⚡3

[Link](true + false);

👉 Output: 1
👉 Why: true → 1, false → 0

⚡4

[Link]([] == false);

👉 Output: true
👉 Why: [] → "" → 0, false → 0

⚡5

[Link](null + 1);

👉 Output: 1
👉 Why: null → 0

⚡6
[Link](undefined + 1);

👉 Output: NaN
👉 Why: undefined → NaN

⚡7

[Link]([] + {});

👉 Output: "[object Object]"

⚡8

[Link]({} + []);

👉 Output: 0

⚡9

[Link](!!"hello");

👉 Output: true

⚡ 10

[Link](typeof NaN);

👉 Output: "number"

⚡ 11

[Link](0 == "0");
[Link](0 === "0");

👉 Output:

true
false

⚡ 12
[Link]([1,2] + [3,4]);

👉 Output: "1,23,4"

⚡ 13

[Link]("2" * "3");

👉 Output: 6

⚡ 14

[Link]("2" + 3 * 2);

👉 Output: "26"

⚡ 15

[Link](typeof []);

👉 Output: "object"

⚡ 16

[Link]([] === []);

👉 Output: false

⚡ 17

let a = {};
let b = a;
b.x = 10;
[Link](a.x);

👉 Output: 10

⚡ 18

[Link](1 < 2 < 3);


👉 Output: true

⚡ 19

[Link](3 > 2 > 1);

👉 Output: false

⚡ 20

[Link]("10" == 10);
[Link]("10" === 10);

👉 Output:

true
false

Perfect. Now we turn this into interview-grade mastery:


👉 Output + Why (short + sharp)

🔥 LEVEL 1 (Fast Clarity)

[Link](2 + "2");

✅ "22"
🧠 number + string → string conversion

[Link]("10" - "5");
✅5
🧠 - forces number conversion

[Link](true + 1);

✅2
🧠 true → 1

[Link](false == 0);

✅ true
🧠 loose equality → false → 0

[Link](null == undefined);

✅ true
🧠 special JS rule (only case)

[Link](typeof []);

✅ "object"
🧠 arrays are objects internally

[Link](typeof null);

✅ "object"
🧠 JS bug

8
[Link]("5" * 2);

✅ 10
🧠 numeric operator → conversion

[Link](0 || "hello");

✅ "hello"
🧠 OR returns first truthy

10

[Link]("" && "world");

✅ ""
🧠 AND returns first falsy

🔥 LEVEL 2 (Tricky)

11

[Link]([] + []);

✅ ""
🧠 [] → "" → string concat

12

[Link]([] + {});

✅ "[object Object]"

13

[Link]({} + []);

✅0
🧠 {} treated as block → +[]
14

[Link]([] == ![]);

✅ true
🧠 ![] → false → [] → "" → 0

15

[Link](!![]);

✅ true
🧠 [] is truthy

16

[Link]([1] == true);

✅ true
🧠 [1] → "1" → 1

17

[Link]("2" + 3 * 2);

✅ "26"
🧠 * first → 6 → string concat

18

[Link](1 < 2 < 3);

✅ true
🧠 1<2 → true → 1<3

19

[Link](3 > 2 > 1);

✅ false
🧠 3>2 → true → 1>1 → false
20

[Link]("a" - 1);

✅ NaN
🧠 invalid number conversion

🔥 LEVEL 3 (Interview Killers)

21

var a = 10;
(function() {
[Link](a);
var a = 20;
})();

✅ undefined
🧠 local a hoisted

22

for (var i = 0; i < 3; i++) {


setTimeout(() => [Link](i), 0);
}

✅333
🧠 shared var

23

for (let i = 0; i < 3; i++) {


setTimeout(() => [Link](i), 0);
}

✅012
🧠 block scope

24
[Link](a);
let a = 5;

❌ ReferenceError
🧠 Temporal Dead Zone

25

const obj = {
name: "JS",
get: function() {
return [Link];
}
};
const fn = [Link];
[Link](fn());

✅ undefined
🧠 this lost (global)

26

[Link]("start");

setTimeout(() => [Link]("timeout"), 0);

[Link]().then(() => [Link]("promise"));

[Link]("end");

start
end
promise
timeout

🧠 microtask > macrotask

27
async function test() {
[Link](1);
await [Link]();
[Link](2);
}
test();
[Link](3);

1
3
2

🧠 await → microtask

28

[Link](NaN == NaN);
[Link](NaN === NaN);

false
false

🧠 NaN not equal to itself

29

[Link](typeof NaN);

✅ "number"

30

[Link]([1,2] == "1,2");

✅ true
🧠 array → string conversion

You might also like