JavaScript
JavaScript
JavaScript
Syllabus
📘Types
PART 1: JavaScript Variables, Data
& Type Coercion
(VERY HIGH interview weight)
Interpreted
Single-threaded
Dynamically typed
Memory-managed (GC)
2. Execution Phase
🔹 var
Function scoped
JavaScript 1
[Link](a);// undefined
var a =10;
[Link](a);// 10
🔹 let
Block scoped
[Link](b);// ❌ ReferenceError
let b =20;
🔹 const
Block scoped
Must be initialized
const x =10;
x =20;// ❌
Error
🔥 Interview Comparison
Feature var let const
JavaScript 2
Feature var let const
number
boolean
null
undefined
symbol
bigint
let a =10;
let b = a;
b =20;
[Link](a);// 10
Array
Function
JavaScript 3
[Link](obj1.x);// 20
typeof10// "number"
typeof"hi"// "string"
typeoftrue// "boolean"
typeofundefined// "undefined"
typeofnull// ❗"object" (BUG in JS)
typeof {}// "object"
typeof []// "object"
typeoffunction(){}// "function"
let a;
[Link](a);// undefined
let b =null;
Number("10")// 10
String(10)// "10"
Boolean(0)// false
== (Loose equality)
Allows type coercion
JavaScript 5
📌 Always use === in real projects
[Link](typeoftypeof10);
✅ Output: "string"
Q2
[Link](null ==undefined);
[Link](null ===undefined);
JavaScript 6
✅ true
✅ false
Q3
let a =10;
let b ="10";
[Link](a + b);
[Link](a - b);
✅ "1010"
✅0
Q4
[Link]([] + []);
[Link]([] + {});
✅ ""
✅ "[object Object]"
1️⃣0️⃣ Common Interview Questions (With Short
Answers)
1. Why let is better than var ?
→ Block scope + avoids bugs + TDZ
2. What is TDZ?
→ Time between hoisting & initialization where access is illegal
3. Is JS statically typed?
→ No, dynamically typed
JavaScript 7
4. Why const object can change?
if (value ==null) {
// handle empty
}
Excellent.
This is where real JavaScript interviews are decided 🔥
JavaScript 8
📘Execution
PART 2: Functions, Scope, Hoisting &
Context
(Most important core JS topic)
If you understand this part well, 50–60% JS interview questions become
easy.
Fully hoisted
🔹 Function Expression
const add =function(a, b) {
return a + b;
};
Treated as a variable
🔹 Arrow Function
constadd = (a, b) => a + b;
Short syntax
JavaScript 9
No own this
No arguments
🔥 Interview Question
❓ Difference between arrow function and normal function?
Feature Normal Arrow
this Dynamic Lexical
arguments Yes No
Constructor Yes No
Default Parameters
functiongreet(name = "Guest") {
[Link](name);
}
greet();// Guest
JavaScript 10
2. Function Scope
3. Block Scope
{
let x =10;
}
// x ❌ not accessible
🔹 Scope Chain
JS looks for variables:
1. Current scope
2. Parent scope
3. Global scope
let x =10;
functionouter() {
let y =20;
functioninner() {
[Link](x, y);
}
inner();
}
outer();
JavaScript 11
But:
[Link](b);// ❌ ReferenceError
let b =20;
🔹 Function Hoisting
hello();// works
functionhello() {
[Link]("Hello");
}
But:
hi();// ❌ TypeError
const hi =function() {
[Link]("Hi");
};
Types:
1. Global Execution Context (GEC)
JavaScript 12
Functions → full definition
Values assigned
🔥 Example Walkthrough
var x =10;
functionfoo() {
var y =20;
[Link](x);
}
foo();
Memory phase:
x → undefined
foo → function
Execution:
x = 10
functiona() {
b();
}
functionb() {
c();
}
functionc() {
JavaScript 13
[Link]("Hello");
}
a();
Stack:
c()
b()
a()
Global
📌 Used to:
Avoid global pollution
functiontest() {
[Link](arguments);
}
test(1,2,3);
[Link](a);
var a =10;
✅ undefined
Q2
foo();
functionfoo() {
[Link]("Hi");
}
✅ Hi
Q3
foo();
var foo =function() {
[Link]("Hello");
};
❌ TypeError
Q4
functionx() {
[Link](a);
}
var a =10;
x();
✅ 10
JavaScript 15
🔥 10️⃣ Common Interview Questions
1. What is execution context?
→ Environment where JS code runs
🔥 Perfect.
This is THE concept that separates average JS devs from strong interview
candidates.
📘Mastery)
PART 3: Closures (In-Depth + Interview
🔹 Basic Example
functionouter() {
let count =0;
functioninner() {
count++;
[Link](count);
}
JavaScript 17
return inner;
}
const fn =outer();
fn();// 1
fn();// 2
📌 still remembers
inner() count
Function is created
🔹 Closure
JavaScript 18
functionouter() {
let x =10;
returnfunctioninner() {
[Link](x);
};
}
5️⃣TRAP)
Closures in Loops (VERY COMMON INTERVIEW
Output:
3
3
JavaScript 19
3
🔥 Why?
var is function scoped
✅ Fix 2: IIFE
for (var i =0; i <3; i++) {
(function(i) {
setTimeout(() =>[Link](i),1000);
})(i);
}
JavaScript 20
}
3️⃣ Memoization
functionmemoize(fn) {
const cache = {};
returnfunction(x) {
if (cache[x])return cache[x];
cache[x] =fn(x);
return cache[x];
};
}
JavaScript 21
functionleak() {
let bigData =newArray(1000000);
returnfunction() {
[Link]("Leaking memory");
};
}
functionx() {
let a =10;
returnfunctiony() {
[Link](a);
};
}
let z =x();
z();
✅ 10
Q2
✅1
JavaScript 22
✅0
Q3
functiontest() {
var x =10;
returnfunction() {
[Link](x++);
};
}
const fn =test();
fn();
fn();
✅ 10
✅ 11
🔥 9️⃣ Interview Questions (With Crisp Answers)
1. What is a closure?
→ Function + lexical scope
2️⃣ Create:
A private counter
A memoized factorial
✅ You’ve Mastered:
✔ Closures
✔ Lexical scoping
✔ Interview traps
✔ Real-world patterns
👉 NEXT PART?
PART 4: Arrays & Array Methods (map, filter, reduce — interview heavy)
Reply Next and we continue building 🔥
Next
Awesome.
Now we enter daily-use + interview-heavy JavaScript territory 🔥
Most coding rounds are array problems.
📘+ Interview
PART 4: Arrays & Array Methods (Deep
Ready)
JavaScript 24
1️⃣ What is an Array?
An array is a collection of elements stored in contiguous memory locations,
indexed from 0 .
JS arrays are:
Dynamic
[Link](5);// add
[Link]();// remove
JavaScript 25
🔹 shift() / unshift() (Start)
[Link]();
[Link](0);
No return
Cannot break
🔹 map() ⭐
const doubled = [Link](x => x *2);
🔹 filter()
How it works:
JavaScript 26
acc → accumulator
0 → initial value
Max
[1,5,2].reduce((a,b) =>[Link](a,b));
Frequency Map
['a','b','a'].reduce((acc, c) => {
acc[c] = (acc[c] ||0) +1;
return acc;
}, {});
🔹 findIndex()
JavaScript 27
[Link](x => x ===3);
🔹 some() / every()
[Link](1,3);
Non-mutating
🔹 splice()
[Link](1,2);
Mutates original
JavaScript 28
🔥FAVORITE)
10️⃣ Shallow vs Deep Copy (INTERVIEW
❌ Shallow Copy
const copy = arr;
[Link]([1,2,3] + [4,5]);
✅ "1,2,34,5"
Q2
JavaScript 29
const arr = [1,2,3];
[Link] =1;
[Link](arr);
✅ [1]
Q3
[Link]([] == []);
✅ false
🔥 1️⃣3️⃣ Interview Questions (With Answers)
1. map vs forEach?
→ map returns new array
2. filter vs find?
→ filter returns array, find returns element
4. slice vs splice?
→ Non-mutating vs mutating
JavaScript 30
7️⃣ Polyfill for reduce
📘+ Interview
PART 5: Objects &
Mastery)
this Keyword (Deep
[Link];
user["age"];
Key is dynamic
🔹 Object Methods
[Link](user);
[Link](user);
[Link](user);
Rename:
Default:
JavaScript 33
1️⃣ this in Global Scope
[Link](this);
Browser → window
[Link] → {}
functiontest() {
[Link](this);
}
test();
Non-strict → window
Strict → undefined
const obj = {
name:"JS",
show() {
[Link]([Link]);
}
};
[Link]();
✅ JS
4️⃣ this Inside Arrow Function
const obj = {
name:"JS",
show:() => {
JavaScript 34
[Link]([Link]);
}
};
[Link]();
❌ undefined
📌 Arrow functions do NOT have their own this
🔹 call
functiongreet(city) {
[Link]([Link], city);
}
[Link]({name:"Alex" },"Hyd");
🔹 apply
[Link]({name:"Alex" }, ["Hyd"]);
🔹 bind
JavaScript 35
const obj = {
name:"A",
fn() {
[Link]([Link]);
}
};
[Link]();
✅A
Q2
const obj = {
name:"A",
fn:() => {
[Link]([Link]);
}
};
[Link]();
❌ undefined
Q3
functionsayHi() {
[Link]([Link]);
}
[Link]({name:"JS" });
✅ JS
🔥 10️⃣ Tricky Interview Questions
1. Why arrow functions don’t have this ?
JavaScript 36
→ They inherit from lexical scope
2. bind vs call?
→ bind returns function, call invokes immediately
📘(Deep
PART 6: Prototypes & Inheritance
+ Interview Mastery)
JavaScript 37
1️⃣Based)
JavaScript is Prototype-Based (NOT Class-
❗ Important:
JavaScript does not have classical inheritance like Java/C++
It uses prototypal inheritance
3️⃣CONFUSION)vs
__proto__ prototype (VERY COMMON
🔹 __proto__
Exists on every object
🔹 prototype
Exists only on constructor functions
JavaScript 38
functionPerson() {}
[Link] =function() {
[Link]("Hi");
};
Prototype chain:
[Link](1);
JS searches:
1. arr
2. [Link]
3. [Link]
[Link] =function() {
JavaScript 39
[Link]([Link]);
};
const u1 =newUser("Alex");
[Link]();// Alex
📌 new does:
2. Sets prototype
3. Binds this
4. Returns object
[Link] =function() {
[Link]("Animal speaks");
};
functionDog(name) {
[Link](this, name);
}
[Link] =[Link]([Link]);
[Link] =Dog;
const d =newDog("Bruno");
[Link]();
sayHi() {
[Link]("Hi " +[Link]);
}
}
classStudentextendsPerson {
constructor(name, id) {
super(name);
[Link] = id;
}
}
const parent = {
greet() {
[Link]("Hello");
}
};
JavaScript 41
};
obj.__proto__.a =2;
[Link](obj.a);// 1
functionA() {}
[Link](A.__proto__ ===[Link]);
✅ true
Q2
✅ true
Q3
✅ Hi
🔥 1️⃣1️⃣ Interview Questions (With Crisp Answers)
JavaScript 42
1. What is prototype?
→ Mechanism for inheritance
🧪 Practice Tasks
1️⃣ Create custom constructor
2️⃣ Implement inheritance manually
3️⃣ Add method to [Link]
✅ You’ve Mastered:
✔ Prototypes
✔ Inheritance
✔ Constructor functions
✔ Classes internals
👉 NEXT PART?
PART 7: Asynchronous JavaScript (Callbacks, Promises, Async/Await, Event
Loop)
🔥 MOST IMPORTANT FOR INTERVIEWS
Reply Next 🚀
Next
JavaScript 43
🔥 Perfect timing — this is THE most important JavaScript topic for
interviews.
If you master this, you will crack async JS questions confidently.
API calls
Timers
Events
without blocking the main thread
Web APIs
Callback Queue
Microtask Queue
Event Loop
Output:
JavaScript 44
A
B
🔹 Asynchronous
[Link]("A");
setTimeout(() =>[Link]("B"),0);
[Link]("C");
Output:
A
C
B
3️⃣ Callbacks
🔹 Basic Callback
functionfetchData(cb) {
setTimeout(() => {
cb("Data loaded");
},1000);
}
fetchData(data =>[Link](data));
❌ Callback Hell
a(() => {
b(() => {
JavaScript 45
c(() => {
d();
});
});
});
🔹 Promise States
pending
fulfilled
rejected
🔹 Consuming Promises
promise
.then(res =>[Link](res))
.catch(err =>[Link](err))
.finally(() =>[Link]("Done"));
[Link]([p1, p2]);
Fails fast
🔹 [Link]
[Link]([p1, p2]);
🔹 [Link]
[Link]([p1, p2]);
🔹 [Link]
[Link]([p1, p2]);
JavaScript 47
asyncfunctionfetchUser() {
try {
const res =awaitfetch(url);
const data =await [Link]();
[Link](data);
}catch (e) {
[Link](e);
}
}
2. Web APIs
3. Microtask Queue
4. Callback Queue
5. Event Loop
[Link]("A");
setTimeout(() =>[Link]("B"),0);
[Link]().then(() =>[Link]("C"));
[Link]("D");
Output:
A
D
C
B
setTimeout(() =>[Link](1),0);
[Link]().then(() =>[Link](2));
[Link](3);
Output:
3
2
1
Q2
JavaScript 49
asyncfunctiontest() {
return"Hello";
}
test().then([Link]);
Output:
Hello
🔥Answers)
1️⃣1️⃣ Common Interview Questions (With
1. What is Event Loop?
→ Manages async tasks
2. Microtask vs Macrotask?
→ Promises > setTimeout
3. Why JS is non-blocking?
→ Event loop + async APIs
4. Promise vs Callback?
→ Avoids hell, better error handling
→ ❌ No
🧪 Practice Tasks
1️⃣ Convert callback to promise
2️⃣ Convert promise to async/await
3️⃣ Predict output for mixed async code
4️⃣ Implement [Link] polyfill
JavaScript 50
✅ You’ve Mastered:
✔ Callbacks
✔ Promises
✔ Async/Await
✔ Event Loop
👉 NEXT PART?
PART 8: Browser APIs, DOM, Events, Debouncing & Throttling
Reply Next 🚀
Next
🔥 Awesome — now we cover Browser + DOM + Performance concepts.
These are must-know for frontend roles & coding rounds.
📘Debouncing
PART 8: Browser APIs, DOM, Events,
& Throttling
(Interview + Real-World Heavy)
<h1id="title">Hello</h1>
const el =[Link]("title");
[Link](".box");
[Link](".box");
🔹 Change Styles
[Link] ="red";
🔹 Create Elements
const div =[Link]("div");
[Link] ="Hello";
[Link](div);
🔹 Capturing
Parent → Child
[Link]("click",e => {
if ([Link] ==="LI") {
[Link]([Link]);
}
});
📌 Improves performance
📌 Handles dynamic elements
7️⃣ Web Storage APIs
🔹 localStorage
JavaScript 53
[Link]("user","Alex");
[Link]("user");
[Link]("user");
🔹 sessionStorage
Exists per tab
🔹 Use Case
Search input
Resize event
functiondebounce(fn, delay) {
let timer;
returnfunction(...args) {
clearTimeout(timer);
timer =setTimeout(() => [Link](this, args), delay);
};
}
🔹 Use Case
Scroll
Button spam
JavaScript 54
functionthrottle(fn, limit) {
let flag =true;
returnfunction(...args) {
if (!flag)return;
flag =false;
[Link](this, args);
setTimeout(() => flag =true, limit);
};
}
[Link] ="";
[Link]([Link]);
✅ Empty body
Q2
[Link]("div").length;
3. localStorage vs sessionStorage?
JavaScript 55
→ Persistent vs per tab
4. Debounce vs Throttle?
→ Delay vs rate-limit
🧪 Practice Tasks
1️⃣ Build debounce search
2️⃣ Throttle scroll logger
3️⃣ Dynamic list click handler
4️⃣ Modal open/close with JS
✅ You’ve Mastered:
✔ DOM manipulation
✔ Events
✔ Performance optimization
👉 NEXT PART?
PART 9: Advanced JS (Currying, Polyfills, Memory, Shallow vs Deep Copy)
🔥 Senior-level interview topics
Reply Next 🚀
Next
🔥 Excellent — this is the final technical depth layer.
These topics are what senior interviewers use to judge real JS understanding.
🔹 Normal Function
functionadd(a, b, c) {
return a + b + c;
}
🔹 Curried Version
functioncurryAdd(a) {
returnfunction(b) {
returnfunction(c) {
return a + b + c;
};
};
}
curryAdd(1)(2)(3);// 6
JavaScript 57
}
🔥 Interview Question
❓ Why currying is useful?
Function reuse
Partial application
Clean code
🔹 Deep Copy
const deep =[Link]([Link](obj));
⚠️ Loses:
JavaScript 58
Functions
Dates
Undefined
Heap → objects/functions
🔹 Garbage Collection
JS removes objects when:
No references exist
[Link] =function(cb) {
const res = [];
for (let i =0; i <[Link]; i++) {
[Link](cb(this[i], i,this));
}
return res;
};
[Link] =function(cb) {
const res = [];
for (let i =0; i <[Link]; i++) {
if (cb(this[i], i,this)) [Link](this[i]);
}
return res;
};
JavaScript 60
[Link] =function(cb, init) {
let acc = init ??this[0];
let start = init ?0 :1;
❌ false
Q2
const a = {x:1 };
const b = {x:1 };
[Link](a == b);
❌ false
Q3
let x =1;
functionfoo() {
[Link](x);
let x =2;
}
JavaScript 61
foo();
❌ ReferenceError (TDZ)
🔥 8️⃣ Interview Questions (Crisp)
1. What is currying?
→ Breaking fn into unary functions
🧪 Practice Tasks
1️⃣ Write curry function
2️⃣ Write deep clone without JSON
3️⃣ Polyfill for
bind
✔ Beginner → Advanced
✔ Real interview patterns
✔ 100% coverage
Reply Next and I’ll give you the complete JS coding practice sheet 💪
Next
🔥🔥 This is it — your FINAL WEAPON for JS interviews & coding rounds.
Below is a COMPLETE JavaScript Coding Practice Sheet, structured exactly
like real interview prep.
If you solve 70–80% of this, you are interview-ready.
📘Sheet
PART 10: JavaScript Coding Practice
(End-to-End)
2. Check palindrome
3. Count vowels
🔹 Numbers
1. Fibonacci series
2. Factorial
4. Armstrong number
JavaScript 63
5. Reverse a number
🔹 Arrays
1. Find max & min
2. Remove duplicates
3. Count occurrences
5. Rotate array
🔹 Strings
1. Anagram check
2. Longest word
3. String compression
🔹 Objects
1. Deep clone object
4. Frequency counter
JavaScript 64
🔵 LEVEL 3: Advanced (🔥 REAL INTERVIEW)
🔹 Functions & Closures
1. Counter using closure
2. Once function
3. Memoization
4. Currying function
5. Compose functions
🔹 Async JavaScript
1. Convert callback → promise
2. Implement [Link]
[Link]([] == ![]);
1.
JavaScript 65
[Link]("5" +3 -2);
1.
let a = {};
let b = a;
b.x =10;
[Link](a.x);
1.
1.
asyncfunctionf() {
return10;
}
[Link](f());
JavaScript 66
7. Deep flatten object
2. Subarray sum
4. Chunk array
5. Shuffle array
🔹 Data Handling
1. Sort objects by key
3. Pagination logic
2. Custom setInterval
JavaScript 68