JavaScript Theory
JavaScript Theory
What is JavaScript
Alright Megha, let’s break this down in a simple, interview-friendly way 👩💻✨
What is JavaScript?
JavaScript is a high-level, interpreted programming language mainly used to make web
pages interactive and dynamic.
If HTML is the structure of a website and CSS is the design, then JavaScript is the brain 🧠
that makes things move, react, and respond.
Since you’ve done ME(A)RN stack training, you already know JavaScript is used in:
Frontend → React
Backend → [Link]
So basically, one language for both sides 🔥
✨ Simple Example
JavaScript
1/235
let name = "Megha";
[Link]("Hello " + name);
Output:
Code
Hello Megha
Synchronous vs Asynchronous
Hoisting & TDZ
ES6 features
Or tricky interview questions
You’re already practicing JS a lot — I can see that from your recent questions 😌
History of JavaScript
Let’s walk through the history of JavaScript in a clean, easy-to-remember way (perfect for
exams + interviews).
2/235
In 1995, JavaScript was created by Brendan Eich
He developed it in just 10 days 😲
It was created for Netscape
The browser was called Netscape Navigator
👉 The goal:
Make web pages interactive (because early websites were completely static).
Originally, it was called Mocha, then LiveScript, and finally renamed to JavaScript (mainly
for marketing — Java was very popular at that time).
📜 Standardization (1997)
In 1997, JavaScript was standardized as ECMAScript
Done by ECMA International
Why?
So that all browsers could follow the same rules and avoid compatibility issues.
3/235
Major update
Introduced:
Strict mode
JSON support
Better array methods
On servers
For backend development
For full-stack apps
This is why MERN stack became possible (which you studied 👀🔥).
🎯 Timeline Summary
4/235
Year Event
You’re building strong fundamentals these days, Megha. I can see the focus 👏
ECMAScript
💡 What is ECMAScript?
ECMAScript is the official standard (set of rules/specifications) that JavaScript follows.
5/235
👉 Simple way to remember:
JavaScript = Implementation
ECMAScript = Standard
Why standardize?
Because different browsers were implementing JavaScript differently (chaos during
browser wars 😅).
🔹 ES5 (2009)
Very important update.
Strict mode
JSON support
Array methods like map() , filter() , forEach()
6/235
This version changed everything. It introduced:
let and const
🎯 Easy Analogy
Think of it like this:
📘 ECMAScript = Rule book
🌍 JavaScript (in Chrome, Firefox, [Link]) = Players following the rule book
Different engines (like Chrome’s V8) implement the ECMAScript standard.
7/235
Since you’re preparing deeply for JS topics lately — want me to explain:
Difference between ES5 and ES6?
What is a JavaScript engine?
Or how V8 works internally?
JavaScript
[Link]("Hello Megha");
👉 So basically:
8/235
V8 is:
Developed by Google
Used in Google Chrome
Also used in [Link]
🔥 Why V8 is powerful?
Converts JS directly into machine code
Uses Just-In-Time (JIT) compilation
Very fast and optimized
Since you learned MERN stack, this engine is literally powering your backend 👀💻
2️⃣ SpiderMonkey
SpiderMonkey is:
Created by Mozilla
Used in Mozilla Firefox
It was actually the first JavaScript engine ever created (1995)
9/235
⚙️ How JavaScript Engines Work (Simplified)
1. Parsing → Converts JS into Abstract Syntax Tree (AST)
2. Interpretation → Converts into bytecode
3. JIT Compilation → Converts frequently used code into machine code
4. Execution
📊 Quick Comparison
Feature V8 SpiderMonkey
10/235
How JS works in browser
The engine:
Reads your JS code
Converts it to machine code
Executes it
11/235
Inside the browser, we have:
🔹 Call Stack
Executes functions
Follows LIFO (Last In, First Out)
🔹 Heap
Stores objects and variables in memory
DOM
fetch()
console
localStorage
🔹 Callback Queue
Stores completed async tasks.
🔹 Event Loop
The boss 😎
It checks:
“Is the call stack empty? If yes, push callback from queue.”
🔄 Step-by-Step Example
JavaScript
12/235
[Link]("Start");
setTimeout(() => {
[Link]("Hello");
}, 2000);
[Link]("End");
What happens?
1️⃣ "Start" → goes to Call Stack → prints
2️⃣ setTimeout → goes to Web API
3️⃣ "End" → prints
4️⃣ After 2 sec → callback moves to Queue
5️⃣ Event Loop pushes it to Call Stack
6️⃣ "Hello" prints
Output:
Code
Start
End
Hello
🧩 Important Concept
JavaScript itself is single-threaded (one call stack).
Web APIs
Event Loop
13/235
“In the browser, JavaScript runs inside a JavaScript engine like V8. The engine uses a call
stack and heap to execute code. For asynchronous operations, the browser provides Web
APIs and a callback queue. The event loop continuously checks if the call stack is empty
and moves callbacks from the queue to the stack, enabling non-blocking behavior.”
Want me to explain the Event Loop deeply next? That’s a favorite interview question 😏
🔥
Yesss 👩💻🔥 now we’re entering backend territory — your MERN brain should like this.
You already know how JS works in the browser. Now let’s see how it works in [Link] —
and what’s different.
🌍 What is [Link]?
[Link] is a JavaScript runtime that allows you to run JavaScript outside the browser,
mainly on servers.
It uses:
So think of it like:
14/235
🧠 How JavaScript Works in [Link] (Architecture)
1️⃣ V8 Engine
Converts JS to machine code
Handles memory (heap) and execution (call stack)
Same as browser.
In [Link] → we have:
⚠️ Important:
[Link] does NOT have DOM.
libuv handles:
Asynchronous I/O
15/235
File system operations
Network operations
Thread pool
🔄 Example in [Link]
JavaScript
const fs = require("fs");
[Link]("Start");
[Link]("End");
Execution Flow:
1️⃣ "Start" → Call Stack
2️⃣ readFile → sent to libuv (background)
16/235
3️⃣ "End" → prints
4️⃣ Once file is read → callback goes to Queue
5️⃣ Event loop pushes it to stack
6️⃣ "File Read" prints
Output:
Code
Start
End
File Read
17/235
What is libuv thread pool?
Microtask queue in [Link]
How Express works internally
<h1>Hello</h1>
<script>
[Link]("Hello Megha");
</script>
18/235
</body>
</html>
JavaScript
[Link]("Welcome Megha");
HTML
<script src="[Link]"></script>
✅ Clean
✅ Reusable
✅ Professional
✅ Used in real projects (like your MERN frontend)
HTML
<head>
<script src="[Link]"></script>
</head>
19/235
Problem:
JS loads before HTML is fully created → DOM may not exist yet.
HTML
<body>
<h1>Hello</h1>
<script src="[Link]"></script>
</body>
Why?
Because HTML loads first → then JS runs.
HTML
<script src="[Link]" defer></script>
HTML
<script src="[Link]" async></script>
Downloads in parallel
Executes immediately when ready
Does NOT guarantee order
20/235
Used mainly for analytics or independent scripts.
DOMContentLoaded
Module scripts ( type="module" )
ES modules import/export
Script loading performance
Variables
Ahhh variables 😌🔥
This is where JavaScript truly starts.
21/235
Let’s make it simple but strong — exam + interview ready.
📌 What is a Variable?
A variable is a container used to store data.
Example:
JavaScript
let name = "Megha";
Here:
name → variable
"Megha" → value
var
let
const
Features:
Function-scoped
Can be redeclared
Can be updated
22/235
Hoisted (but initialized as undefined)
Features:
Block-scoped
Can be updated
Cannot be redeclared in same scope
Hoisted but in TDZ (Temporal Dead Zone)
Features:
Block-scoped
Cannot be updated
Cannot be redeclared
Must be initialized at declaration
23/235
}
[Link](a); // Error
Can update? ✅ ✅ ❌
Can redeclare? ✅ ❌ ❌
🎯 Best Practice
👉 Use const by default
👉 Use let when value changes
👉 Avoid var
24/235
var
Even though we don’t use it much now, interviews love asking about it. So let’s understand
it properly.
📌 What is var ?
var is the old way of declaring variables in JavaScript (before ES6).
JavaScript
var name = "Megha";
[Link](name);
JavaScript
function test() {
var a = 10;
}
[Link](a); // ❌ Error
JavaScript
if (true) {
var b = 20;
}
[Link](b); // ✅ 20
Why?
Because var ignores block {} and only respects functions.
25/235
2️⃣ Can Be Redeclared
JavaScript
var x = 5;
var x = 10;
[Link](x); // 10
No error 😬
This can create bugs in large applications.
Example:
JavaScript
[Link](a);
var a = 10;
Output:
Code
undefined
JavaScript
var a; // hoisted
[Link](a);
26/235
a = 10;
let
Alright Megha 👩💻✨ let’s talk about let — the modern, safer upgrade from var .
This is a favorite interview topic because it connects to block scope + hoisting + TDZ 🔥
📌 What is let ?
let is used to declare variables in JavaScript (introduced in ES6 / ES2015).
JavaScript
27/235
let name = "Megha";
[Link](name);
JavaScript
if (true) {
let a = 10;
}
[Link](a); // ❌ Error
This makes code safer and avoids accidental access outside the block.
28/235
JavaScript
[Link](a);
let a = 10;
Output:
Code
ReferenceError
Why?
👉 TDZ = The time between variable declaration and initialization where the variable
cannot be accessed.
Internally:
JavaScript
// a is hoisted but uninitialized
let a;
Redeclare ✅ Yes ❌ No
29/235
Value may change
Inside loops
Inside conditions
Temporary variables
JavaScript
for (let i = 0; i < 3; i++) {
setTimeout(() => [Link](i), 1000);
}
Output:
Code
0
1
2
Code
3
3
3
TDZ in detail
30/235
How variables are stored in memory (Execution Context)
Or tricky closure examples
const
Ahhh const 😌🔥
This one looks simple… but interviews LOVE twisting it.
📌 What is const ?
const is used to declare variables whose value cannot be reassigned.
JavaScript
const name = "Megha";
[Link](name);
JavaScript
if (true) {
const a = 10;
}
[Link](a); // ❌ Error
31/235
JavaScript
const age = 25;
age = 30; // ❌ Error
JavaScript
const city = "Kochi"; // ✅
Example:
JavaScript
const person = {
name: "Megha"
};
32/235
[Link] = "Anna"; // ✅ Allowed
[Link]([Link]);
Output:
Code
Anna
JavaScript
person = { name: "New" }; // ❌ Error
Memory view:
Update ✅ ✅ ❌
Redeclare ✅ ❌ ❌
Must initialize? ❌ ❌ ✅
33/235
🎯 Best Practice (Modern JS)
👉 Use const by default
👉 Use let only when value changes
👉 Avoid var
let
const
👉 How variables are stored in memory (Execution Context + Memory Creation Phase)
👉 Or TDZ deep explanation
👉 Or tricky closure question with const
34/235
📌 Variable Naming Rules in JavaScript
When declaring variables using var , let , or const , you must follow certain rules.
✔ Valid examples:
JavaScript
let name = "Megha";
let _age = 25;
let $price = 100;
JavaScript
let name1 = "Megha"; // ✅ Valid
JavaScript
let user-name = "Megha"; // ❌
let user@name = "Megha"; // ❌
let
const
var
if
else
function
return
class
etc.
JavaScript
let function = 10; // ❌ Error
JavaScript is case-sensitive.
🔹 Constants in UPPER_CASE
36/235
JavaScript
const PI = 3.14;
const MAX_LIMIT = 100;
Better:
JavaScript
let width = 10;
let height = 20;
Data types
Hoisting
Execution context
Primitive vs reference types
37/235
Temporal Dead Zone (TDZ)
Ahhh TDZ 😏🔥
Now we’re stepping into real JavaScript understanding territory.
let
const
NOT to:
var
🧠 Simple Example
JavaScript
[Link](a);
let a = 10;
Output:
Code
ReferenceError
38/235
Why?
Code
a → allocated in memory (but not initialized)
JavaScript
[Link](x);
var x = 10;
Output:
Code
undefined
Why?
Hoisted
Initialized with undefined
39/235
📍 Where Does TDZ Start & End?
TDZ starts:
👉 At the beginning of the block
TDZ ends:
👉 At the line where variable is initialized
Example:
JavaScript
{
// TDZ starts here
[Link](a); // ❌ Error
[Link](a); // ✅ 5
}
JavaScript
let total = price * 2;
let price = 100;
40/235
🧠 Bonus: TDZ Trick Question
What happens here?
JavaScript
let a = 10;
{
[Link](a);
let a = 20;
}
Answer:
💥 ReferenceError
Data Types
Yesss Megha 👩💻🔥 now we’re at one of the most important JS fundamentals — Data
Types.
41/235
📌 What Are Data Types?
Data types define the type of value a variable can hold.
Example:
JavaScript
let name = "Megha"; // String
let age = 25; // Number
1. String
Text values.
JavaScript
let name = "Megha";
2. Number
Integers and decimals.
JavaScript
let age = 25;
let price = 99.99;
42/235
3. Boolean
True or false.
JavaScript
let isLoggedIn = true;
4. Undefined
Declared but not assigned.
JavaScript
let x;
[Link](x); // undefined
5. Null
Intentional empty value.
JavaScript
let data = null;
⚠️ Interview twist:
typeof null returns "object" (this is a historical bug in JavaScript).
6. BigInt
For very large numbers.
JavaScript
let big = 12345678901234567890n;
7. Symbol
Unique identifier.
43/235
JavaScript
let id = Symbol("id");
Object
Most important non-primitive type.
JavaScript
let person = {
name: "Megha",
age: 25
};
JavaScript
let numbers = [1, 2, 3, 4];
JavaScript
function greet() {
[Link]("Hello");
}
44/235
JavaScript
let a = 10;
let b = a;
b = 20;
[Link](a); // 10
JavaScript
let obj1 = { name: "Megha" };
let obj2 = obj1;
[Link] = "Anna";
[Link]([Link]); // Anna
🎯 typeof Operator
We use typeof to check data type:
JavaScript
[Link](typeof "Hello"); // string
[Link](typeof 10); // number
[Link](typeof true); // boolean
[Link](typeof {}); // object
String Object
Number Array
Boolean Function
45/235
Primitive Reference
Undefined
Null
BigInt
Symbol
🔹 1️⃣ String
Used to store text.
JavaScript
let name = "Megha";
let city = 'Kochi';
JavaScript
let str = "Hi";
str[0] = "B";
[Link](str); // Still "Hi"
🔹 2️⃣ Number
Used for both integers and decimals.
JavaScript
let age = 25;
let price = 99.99;
JavaScript
Infinity
-Infinity
NaN
47/235
🔹 3️⃣ Boolean
Represents true or false.
JavaScript
let isLoggedIn = true;
let isAdmin = false;
🔹 4️⃣ Undefined
A variable that is declared but not assigned a value.
JavaScript
let x;
[Link](x); // undefined
🔹 5️⃣ Null
Represents intentional empty value.
JavaScript
let data = null;
⚠️ Interview twist:
JavaScript
[Link](typeof null); // "object"
🔹 6️⃣ BigInt
48/235
Used for very large numbers beyond normal limit.
JavaScript
let big = 123456789012345678901234567890n;
🔹 7️⃣ Symbol
Used to create unique identifiers.
JavaScript
let id = Symbol("userID");
JavaScript
Symbol("a") === Symbol("a"); // false
JavaScript
let a = 10;
let b = a;
b = 20;
[Link](a); // 10
[Link](b); // 20
📊 Summary Table
49/235
Data Type Example
String "Hello"
Number 10 , 3.14
Undefined let x;
Null null
BigInt 123n
Symbol Symbol()
Yesss 👩💻🔥 now we’re stepping into Non-Primitive (Reference) Data Types — this is
where JavaScript starts getting interesting.
50/235
You already know primitives store values directly.
Now let’s see what happens when things get stored by reference.
Object
Array
Function
🔹 1️⃣ Object
An object stores key-value pairs.
JavaScript
let person = {
name: "Megha",
age: 25
};
[Link]([Link]); // Megha
JavaScript
[Link] = 26;
[Link]([Link]); // 26
JavaScript
let numbers = [10, 20, 30];
[Link](numbers[0]); // 10
JavaScript
[Link](40);
[Link](numbers); // [10, 20, 30, 40]
JavaScript
function greet() {
[Link]("Hello Megha");
}
greet();
JavaScript
let sayHi = function() {
[Link]("Hi");
};
JavaScript
let obj1 = { name: "Megha" };
let obj2 = obj1;
[Link] = "Anna";
52/235
[Link]([Link]); // Anna
Because:
Both obj1 and obj2 point to the same memory location in heap.
Mutable ❌ No ✅ Yes
Code
a → 10
b → 10 (separate copy)
Reference:
Code
obj1 → (Heap Address 101)
obj2 → (Heap Address 101)
53/235
🎯 Interview Answer (Perfect Version)
“Non-primitive data types in JavaScript include objects, arrays, and functions. They are
stored in heap memory, and variables hold references to their memory addresses. Unlike
primitive types, non-primitive types are mutable and copied by reference.”
Operators
Let’s break them into clean categories so it sticks in your brain permanently 👩💻✨
Example:
JavaScript
let a = 10;
let b = 5;
[Link](a + b); // 15
Here + is an operator.
54/235
🔹 1️⃣ Arithmetic Operators
Used for mathematical calculations.
JavaScript
let a = 10;
let b = 3;
JavaScript
let x = 10; // =
x += 5; // x = x + 5
x -= 2;
x *= 3;
x /= 2;
x %= 2;
JavaScript
[Link](5 == "5"); // true (loose equality)
[Link](5 === "5"); // false (strict equality)
[Link](10 != 5); // true
[Link](10 > 5); // true
[Link](10 <= 5); // false
🔥 Important:
== → compares value only
55/235
=== → compares value + type (recommended)
JavaScript
let a = true;
let b = false;
JavaScript
let x = 5;
[Link](++x); // 6 (pre-increment)
[Link](x--); // post-decrement
56/235
[Link](typeof "Megha"); // string
JavaScript
let arr1 = [1, 2];
let arr2 = [...arr1, 3, 4];
JavaScript
let obj = {};
[Link]([Link]?.first); // undefined (no error)
Type coercion
== vs === deep explanation
Short-circuit evaluation
57/235
Bitwise operators
Arithmetic
Yesss 👏 arithmetic operators — the most straightforward ones, but still super important.
They work with numbers (and sometimes strings 👀 — we’ll see that twist).
🔹 1️⃣ Addition ( + )
JavaScript
let a = 10;
let b = 5;
[Link](a + b); // 15
JavaScript
[Link]("Hello " + "Megha"); // Hello Megha
[Link](10 + "5"); // "105"
🔹 2️⃣ Subtraction ( - )
JavaScript
[Link](10 - 5); // 5
58/235
Interesting case:
JavaScript
[Link]("10" - 5); // 5
🔹 3️⃣ Multiplication ( * )
JavaScript
[Link](4 * 5); // 20
JavaScript
[Link]("4" * 5); // 20
🔹 4️⃣ Division ( / )
JavaScript
[Link](10 / 2); // 5
Division by zero:
JavaScript
[Link](10 / 0); // Infinity
🔹 5️⃣ Modulus ( % )
Returns remainder.
JavaScript
[Link](10 % 3); // 1
Used for:
59/235
Checking even/odd
Loop patterns
Pagination logic
Example:
JavaScript
if (10 % 2 === 0) {
[Link]("Even");
}
🔹 6️⃣ Exponentiation ( ** )
JavaScript
[Link](2 ** 3); // 8
2 raised to power 3.
JavaScript
let x = 5;
[Link](++x); // 6
Post-increment
JavaScript
let y = 5;
[Link](y++); // 5
[Link](y); // 6
60/235
🧠 Operator Precedence
Example:
JavaScript
[Link](10 + 5 * 2); // 20
JavaScript
[Link]((10 + 5) * 2); // 30
Assignment
Nice 👏 now we’re talking about Assignment Operators — simple concept, but super
important in real coding.
61/235
📌 What Are Assignment Operators?
Assignment operators are used to assign values to variables.
JavaScript
let x = 10;
Important:
= does NOT mean “equals” like in math.
Instead of writing:
JavaScript
x = x + 5;
We write:
JavaScript
x += 5;
62/235
Let’s see all common ones 👇
➕ Addition Assignment ( += )
JavaScript
let x = 10;
x += 5; // x = x + 5
[Link](x); // 15
➖ Subtraction Assignment ( -= )
JavaScript
let x = 10;
x -= 3; // x = x - 3
[Link](x); // 7
✖ Multiplication Assignment ( *= )
JavaScript
let x = 4;
x *= 2; // x = x * 2
[Link](x); // 8
➗ Division Assignment ( /= )
JavaScript
let x = 10;
x /= 2; // x = x / 2
[Link](x); // 5
➗ Modulus Assignment ( %= )
JavaScript
63/235
let x = 10;
x %= 3; // x = x % 3
[Link](x); // 1
JavaScript
let a = true;
a &&= false;
[Link](a); // false
OR Assignment ( ||= )
JavaScript
let a = false;
a ||= true;
[Link](a); // true
64/235
JavaScript
let a = null;
a ??= "Default";
[Link](a); // Default
🧠 Interview Trap
Difference between:
JavaScript
let x = 5;
x = x + 5;
and
JavaScript
x += 5;
👉 No difference in result.
👉 Second one is just shorthand.
Comparison operators
== vs === deep dive
65/235
Type coercion
Comparison Operators
Yesss 👏 now we’re into Comparison Operators — this is where logic decisions start
happening 🔥
if statements
Loops
Filtering data
Authentication checks
React conditional rendering 👀
👉 true
or
👉 false
Why true?
66/235
JavaScript converts "5" to number 5 before comparison.
Why false?
Because:
=== checks:
✔ Value
✔ Type
No type conversion.
67/235
🔹 5️⃣ Greater Than ( > )
JavaScript
[Link](10 > 5); // true
🆚 Quick Table
68/235
Operator Meaning Type Checked?
== Equal ❌ No
!= Not Equal ❌ No
Logical operators
Short-circuit evaluation
Type coercion deep dive
Truthy & Falsy values
logical
69/235
You use these everywhere:
if statements
Authentication logic
Form validation
React conditional rendering
API checks
They return:
👉 true
👉 false
👉 OR sometimes the actual value (important 👀)
&& (AND)
|| (OR)
! (NOT)
JavaScript
[Link](true && true); // true
[Link](true && false); // false
Example:
JavaScript
let age = 20;
let hasID = true;
70/235
if (age >= 18 && hasID) {
[Link]("Allowed");
}
🔹 2️⃣ OR ( || )
Returns true if at least one condition is true.
JavaScript
[Link](true || false); // true
[Link](false || false); // false
Example:
JavaScript
let isAdmin = false;
let isEditor = true;
if (isAdmin || isEditor) {
[Link]("Access Granted");
}
🔹 3️⃣ NOT ( ! )
Reverses the boolean value.
JavaScript
[Link](!true); // false
[Link](!false); // true
Example:
JavaScript
let isLoggedIn = false;
if (!isLoggedIn) {
71/235
[Link]("Please login");
}
AND Short-Circuit
JavaScript
[Link](0 && "Hello"); // 0
[Link]("Hi" && "Megha"); // "Megha"
Rule:
OR Short-Circuit
JavaScript
[Link](null || "Guest"); // "Guest"
[Link]("Admin" || "User"); // "Admin"
Rule:
false
0
""
72/235
null
undefined
NaN
Arithmetic
Assignment
Comparison
Logical
73/235
Bitwise
Ooo okayyy 😌🔥 now we’re entering slightly “low-level brain” territory — Bitwise
Operators.
Not used daily in frontend work, but interviews love asking basics.
Example:
Code
5 in binary = 00000101
3 in binary = 00000011
JavaScript
[Link](5 & 3);
Binary:
Code
5 → 0101
3 → 0011
------------
0001
Result:
74/235
Code
1
🔹 2️⃣ Bitwise OR ( | )
Returns 1 if at least one bit is 1.
JavaScript
[Link](5 | 3);
Binary:
Code
0101
0011
-------
0111
Result:
Code
7
JavaScript
[Link](5 ^ 3);
Binary:
Code
0101
0011
-------
0110
75/235
Result:
Code
6
JavaScript
[Link](~5);
Result:
Code
-6
⚠️ Why negative?
Formula shortcut:
Code
~n = -(n + 1)
So:
Code
~5 = -(5 + 1) = -6
JavaScript
[Link](5 << 1);
76/235
Binary:
Code
0101 → 1010
Result:
Code
10
(5 × 2 = 10)
JavaScript
[Link](8 >> 1);
Binary:
Code
1000 → 0100
Result:
Code
4
JavaScript
if ((num & 1) === 0) {
[Link]("Even");
}
Ternary
78/235
📌 What is the Ternary Operator?
The ternary operator is a shortcut for if-else.
Syntax:
JavaScript
condition ? value_if_true : value_if_false;
1. Condition
2. True result
3. False result
🔹 Basic Example
Normal if-else :
JavaScript
let age = 18;
JavaScript
let age = 18;
let result = age >= 18 ? "Adult" : "Minor";
[Link](result);
Much shorter 👌
🔹 How It Works
79/235
JavaScript
condition ? expression1 : expression2;
[Link](grade);
80/235
🧠 Important: It Returns a Value
Ternary is an expression, not just a statement.
JavaScript
let status = isAdmin ? "Admin" : "User";
81/235
Let’s clear that confusion permanently.
Syntax:
JavaScript
value1 ?? value2
🔹 Basic Example
JavaScript
let username = null;
let result = username ?? "Guest";
[Link](result); // Guest
[Link](result); // Megha
82/235
🔥 Very Important: Difference Between || and ??
This is the interview trap.
OR Operator ( || )
|| returns right value if left value is falsy.
Falsy values:
false
0
""
null
undefined
NaN
Example:
JavaScript
let count = 0;
[Link](count || 10); // 10 ❗
Why?
Because 0 is falsy.
Nullish Coalescing ( ?? )
Only checks for:
null
undefined
JavaScript
let count = 0;
[Link](count ?? 10); // 0 ✅
83/235
🧠 Practical Use Case
When you want default value but allow 0 or empty string.
Example:
JavaScript
let price = 0;
let finalPrice = price ?? 100;
[Link](finalPrice); // 0
JavaScript
let user = {};
[Link]([Link]?.name ?? "Guest");
` `
84/235
“The nullish coalescing operator (??) returns the right-hand value only when the left-hand
value is null or undefined. Unlike the logical OR operator (||), it does not treat other falsy
values like 0 or empty string as false. It is commonly used to provide default values safely.”
Optional chaining ( ?. )
Type coercion deep dive
Short-circuit evaluation
Control statements (if, switch)
Ooo yes 😌🔥
Optional chaining is one of those “once you start using it, you can’t go back” features.
Syntax:
JavaScript
object?.property
85/235
🔹 Problem Without Optional Chaining
JavaScript
let user = {};
[Link]([Link]);
💥 Error:
Code
Cannot read properties of undefined
[Link]([Link]?.name);
Output:
Code
undefined
🔥 How It Works
JavaScript
object?.property
Internally it checks:
JavaScript
object == null ? undefined : [Link]
86/235
If the left side is null or undefined , it stops immediately.
🔹 Nested Example
JavaScript
let user = {
profile: {
address: {
city: "Kochi"
}
}
};
[Link]([Link]?.address?.city);
[Link](users?.[0]);
87/235
[Link]?.(); // calls function safely
?.
Logical operators
Comparison operators
88/235
Functions deep dive
Execution context
typeof operator
Ahhh typeof 😌🔥
Simple-looking operator… but interviewers LOVE throwing tricky questions with it.
📌 What is typeof ?
typeof is a unary operator used to check the data type of a value.
Syntax:
JavaScript
typeof value;
🔹 Basic Examples
JavaScript
[Link](typeof "Megha"); // "string"
[Link](typeof 25); // "number"
[Link](typeof true); // "boolean"
🔹 For Undefined
JavaScript
let x;
[Link](typeof x); // "undefined"
89/235
🔥 Important Interview Twist: null
JavaScript
[Link](typeof null); // "object"
🔹 For Objects
JavaScript
let person = { name: "Megha" };
[Link](typeof person); // "object"
🔹 For Arrays
JavaScript
let arr = [1, 2, 3];
[Link](typeof arr); // "object"
JavaScript
[Link]([Link](arr)); // true
🔹 For Functions
JavaScript
90/235
function greet() {}
[Link](typeof greet); // "function"
"Hello" "string"
10 "number"
true "boolean"
undefined "undefined"
null "object" ❗
{} "object"
[] "object"
function(){} "function"
10n "bigint"
Symbol() "symbol"
Output:
Code
"undefined"
No error thrown.
JavaScript
[Link](notDeclared);
Type coercion
== vs === deep dive
Execution context
Stack vs Heap
Functions
92/235
delete operator
Syntax:
JavaScript
delete [Link];
It returns:
delete [Link];
[Link](user);
// { name: "Megha" }
🔹 Return Value
93/235
JavaScript
let obj = { a: 10 };
JavaScript
let x = 10;
delete x; // false
🔹 Array Example
JavaScript
let arr = [10, 20, 30];
delete arr[1];
[Link](arr);
Output:
JavaScript
[10, empty, 30]
⚠️ Important:
delete removes the value but does NOT reindex the array.
JavaScript
94/235
[Link](1, 1);
🔥 Non-Configurable Properties
Some properties cannot be deleted.
Example:
JavaScript
var y = 10;
delete y; // false
🧠 Important Clarification
delete :
📊 Quick Summary
Case Works?
95/235
Case Works?
let variable ❌ No
const variable ❌ No
var variable ❌ No
in operator
instanceof
Execution context
Functions
Loops
- if / else
-
- switch
-
- Nested conditions
-
96/235
- for loop
-
- while loop
-
- do-while loop
-
- for…in
-
- for…of
-
- break
-
- continue
-
- Labels
Yesss Megha 🔥 now we’re entering Control Flow & Logic Building — this is where real
problem-solving starts.
🔹 1️⃣ if / else
Used to execute code based on a condition.
JavaScript
let age = 20;
JavaScript
let marks = 75;
97/235
[Link]("B");
} else {
[Link]("C");
}
🔹 2️⃣ switch
Used when checking multiple exact values.
JavaScript
let day = 2;
switch (day) {
case 1:
[Link]("Monday");
break;
case 2:
[Link]("Tuesday");
break;
default:
[Link]("Invalid day");
}
Best for:
Menu selection
Fixed value matching
JavaScript
let age = 20;
let hasID = true;
98/235
[Link]("ID Required");
}
}
JavaScript
for (let i = 0; i < 5; i++) {
[Link](i);
}
Structure:
JavaScript
for (initialization; condition; increment)
JavaScript
let i = 0;
while (i < 5) {
[Link](i);
i++;
}
99/235
JavaScript
let i = 0;
do {
[Link](i);
i++;
} while (i < 5);
Key difference:
Condition is checked after execution.
🔹 7️⃣ for…in
Used to iterate over object properties.
JavaScript
let user = {
name: "Megha",
age: 25
};
Best for:
Objects
🔹 8️⃣ for…of
Used to iterate over iterable values.
JavaScript
let arr = [10, 20, 30];
100/235
Best for:
Arrays
Strings
Maps
Sets
🔹 9️⃣ break
Stops loop immediately.
JavaScript
for (let i = 0; i < 10; i++) {
if (i === 5) {
break;
}
[Link](i);
}
🔹 🔟 continue
Skips current iteration.
JavaScript
for (let i = 0; i < 5; i++) {
if (i === 2) {
continue;
}
[Link](i);
}
Output skips 2.
JavaScript
101/235
outerLoop:
for (let i = 0; i < 3; i++) {
for (let j = 0; j < 3; j++) {
if (i === 1 && j === 1) {
break outerLoop;
}
[Link](i, j);
}
}
Megha 👀🔥
Now your fundamentals are seriously strong.
practical questions
You’ve covered operators + loops + conditions — now it’s time to apply logic.
102/235
I’ll give you practical questions from easy → medium → slightly tricky (interview level).
Try solving them before looking at the solution part.
Example:
Code
Input: 7
Output: Odd
Code
1 2 3 4 5 6 7 8 9 10
103/235
🟡 Level 2 – Slightly Better Logic
5️⃣ Reverse a String
Code
Input: "megha"
Output: "ahgem"
If divisible by 3 → "Fizz"
If divisible by 5 → "Buzz"
If divisible by both → "FizzBuzz"
104/235
🔟 Palindrome Check
Code
Input: "madam"
Output: True
Output:
a = 10
b = 5
105/235
Input: [10, 5, 8, 20, 15]
Output: 15
Option 2:
You say “show solutions” and I’ll give optimized answers.
Option 3:
We do mock interview mode — I give you one question randomly and you answer
instantly.
You’ve built strong fundamentals. Now let’s test your logic power 💪😌
🟢 STRING QUESTIONS
106/235
👉 With methods
👉 Without methods (loop only)
Example:
Code
Input: "megha"
Output: "ahgem"
Try:
Using split() , reverse() , join()
Without using reverse method
107/235
Input: "programming"
Output: "progamin"
🟡 ARRAY QUESTIONS
Try:
Using Set
Without using Set
Try:
Using [Link]
Without methods
Try:
Using reduce
108/235
Using loop
Try:
Using shift() and push()
Without using them
Try:
Using spread ...
Using loop
🟠 NUMBER QUESTIONS
Try:
Using string conversion
Using math only
109/235
1️⃣2️⃣ Armstrong Number
Code
Input: 153
Output: true
🔴 LOGIC + CONDITIONS
110/235
1️⃣7️⃣ Move All Zeros to End
Code
Input: [0,1,0,3,12]
Output: [1,3,12,0,0]
Try:
Using filter
Without filter
Try:
Using flat()
Without using flat
Now Megha 👀🔥
Do you want:
Yesss Megha 🔥💪
Here’s a clean, structured list of practical JavaScript questions — perfect for logic
building, interviews, and revision.
112/235
2. Check if a number is positive, negative, or zero
3. Find the largest of two numbers
4. Find the largest of three numbers
5. Swap two numbers (with and without third variable)
6. Print numbers from 1 to N
7. Print even numbers from 1 to N
8. Find sum of first N natural numbers
9. Find factorial of a number
10. Print multiplication table of a number
113/235
🟠 4️⃣ Array-Based Questions
31. Find largest number in array
32. Find smallest number in array
33. Find second largest number
34. Remove duplicates from array
35. Count frequency of array elements
36. Find sum of array elements
37. Reverse an array
38. Rotate array left/right
39. Find missing number in array
40. Move all zeros to end
114/235
57. Sort object by values
58. Check if object is empty
59. Group array of objects by property
60. Remove duplicate objects from array
115/235
82. Create a stopwatch
83. Validate email format
84. Check password strength
85. Pagination logic
86. Implement search filter
87. Sort table data
88. Create basic todo app logic
89. Find total price in cart
90. Remove item from cart
Megha 👀🔥
If you practice even 60–70% of this properly, your JS logic becomes very strong.
116/235
# Functions (Very Important)
- Function declaration
-
- Function expression
-
- Arrow functions
-
- Anonymous functions
-
- IIFE
-
- Default parameters
-
- Rest parameters
-
- Callback functions
-
- Higher-order functions
-
- Pure vs impure functions
-
- Recursion
-
- Closures
-
- Lexical scope
-
- Hoisting
-
- Function overloading (concept)
-
- Arguments object
JavaScript
function greet() {
[Link]("Hello Megha");
}
✔ Hoisted
✔ Can be called before definition
JavaScript
greet(); // works
JavaScript
const greet = function() {
[Link]("Hello");
};
JavaScript
const greet = () => {
[Link]("Hello");
};
Short form:
JavaScript
const add = (a, b) => a + b;
118/235
🔥 Important:
No own this
No arguments object
Cannot be used as constructor
JavaScript
setTimeout(function() {
[Link]("Hi");
}, 1000);
JavaScript
(function() {
[Link]("Runs immediately");
})();
Used for:
greet(); // Guest
119/235
If argument not passed → default used.
JavaScript
function sum(...numbers) {
return [Link]((a, b) => a + b, 0);
}
✔ Modern
✔ Better than arguments
JavaScript
function greet(name, callback) {
[Link]("Hi " + name);
callback();
}
greet("Megha", function() {
[Link]("Welcome!");
});
Used in:
Event handling
Async programming
Array methods
120/235
Example:
JavaScript
function multiplyBy(num) {
return function(x) {
return x * num;
};
}
map
filter
reduce
JavaScript
function add(a, b) {
return a + b;
}
❌ Impure Function
Depends on external variable
Modifies outside data
JavaScript
let total = 0;
function addToTotal(x) {
total += x;
}
121/235
🔹 1️⃣1️⃣ Recursion
Function calling itself.
JavaScript
function factorial(n) {
if (n === 1) return 1;
return n * factorial(n - 1);
}
Must have:
✔ Base case
✔ Recursive call
JavaScript
function outer() {
let count = 0;
return function() {
count++;
[Link](count);
};
}
JavaScript
122/235
function outer() {
let name = "Megha";
function inner() {
[Link](name);
}
inner();
}
🔹 1️⃣4️⃣ Hoisting
Function declarations are hoisted:
JavaScript
greet();
function greet() {
[Link]("Hi");
}
JavaScript
function add(a) {}
function add(a, b) {} // overrides
JavaScript
function add(a, b) {
if (b === undefined) return a;
123/235
return a + b;
}
JavaScript
function show() {
[Link](arguments);
}
show(1, 2, 3);
Megha 👀🔥
This section is VERY important for MERN interviews.
Execution context
Call stack
Bind, call, apply
Event loop
124/235
# Arrays (Complete)
- Array creation
-
- Indexing
-
- Iteration
-
- Basic methods:
- push
-
- pop
-
- shift
-
- unshift
-
- Advanced methods:
- map
-
- filter
-
- reduce
-
- forEach
-
- find
-
- findIndex
-
- some
-
- every
-
- includes
-
- flat
-
- flatMap
-
125/235
- slice
-
- splice
-
- sort
-
- reverse
-
- join
-
- Spread operator
-
- Destructuring arrays
JavaScript
let arr = [1, 2, 3, 4];
JavaScript
let arr = new Array(1, 2, 3);
🔹 2️⃣ Indexing
Arrays are zero-indexed.
JavaScript
126/235
let arr = ["A", "B", "C"];
[Link](arr[0]); // A
[Link](arr[2]); // C
JavaScript
arr[[Link] - 1];
🔹 3️⃣ Iteration
Using for loop
JavaScript
for (let i = 0; i < [Link]; i++) {
[Link](arr[i]);
}
Using for...of
JavaScript
for (let value of arr) {
[Link](value);
}
127/235
JavaScript
[Link]();
JavaScript
let nums = [1, 2, 3];
let doubled = [Link](n => n * 2);
128/235
JavaScript
let sum = [Link]((acc, curr) => acc + curr, 0);
🔥 findIndex()
JavaScript
[Link](n => n > 2);
🔥 includes()
129/235
JavaScript
[Link](3);
🔥 flat()
JavaScript
let arr = [1, [2, 3]];
[Link](); // [1,2,3]
🔥 flatMap()
JavaScript
let arr = [1, 2];
[Link](n => [n, n * 2]);
🔥 sort()
⚠️ Default sorts as string.
JavaScript
[Link]((a, b) => a - b);
130/235
🔥 reverse()
JavaScript
[Link]();
🔥 join()
JavaScript
[Link]("-");
JavaScript
let copy = [...arr];
Merge arrays:
JavaScript
let merged = [...arr1, ...arr2];
JavaScript
let arr = [10, 20, 30];
Skip values:
JavaScript
let [first, , third] = arr;
131/235
Rest with destructuring:
JavaScript
let [first, ...rest] = arr;
map ✅ ❌
filter ✅ ❌
reduce ✅ ❌
forEach ❌ ❌
push ❌ ✅
splice ❌ ✅
slice ✅ ❌
Megha 👀🔥
If you master:
map
filter
reduce
132/235
sort (with compare function)
slice vs splice
Objects (Complete)
this keyword
Execution context
Prototypes
Async JS
# Objects (Complete)
133/235
🔹 1️⃣ Object Creation Methods
✅ 1. Object Literal (Most Common)
JavaScript
let user = {
name: "Megha",
age: 25
};
JavaScript
let user = new Object();
[Link] = "Megha";
[Link] = 25;
✅ 3. Constructor Function
JavaScript
function User(name, age) {
[Link] = name;
[Link] = age;
}
✅ 4. [Link]()
JavaScript
let obj = [Link](null);
134/235
🔹 2️⃣ Object Literals
Most readable and preferred method.
JavaScript
let person = {
name: "Megha",
greet() {
[Link]("Hello");
}
};
JavaScript
let user = {
name: "Megha",
greet: function() {
[Link]("Hi");
}
};
JavaScript
[Link]
Bracket Notation
JavaScript
user["name"]
135/235
Key has spaces
JavaScript
let key = "age";
user[key];
[Link]([Link]);
Safe access:
JavaScript
[Link]?.address?.city
🔥 [Link]()
JavaScript
[Link](user);
🔥 [Link]()
136/235
JavaScript
[Link](user);
🔥 [Link]()
JavaScript
[Link](user);
🔥 [Link]()
Merge objects:
JavaScript
let newObj = [Link]({}, obj1, obj2);
🔥 [Link]()
Prevents modification.
JavaScript
[Link](user);
🔥 [Link]()
Prevents add/delete but allows update.
JavaScript
[Link](user);
137/235
🔥 hasOwnProperty()
JavaScript
[Link]("name");
JavaScript
let user = {
name: "Megha",
greet() {
[Link]([Link]);
}
};
JavaScript
let user = { name: "Megha", age: 25 };
Rename:
JavaScript
let { name: userName } = user;
Default value:
JavaScript
let { city = "Kochi" } = user;
138/235
🔹 9️⃣ Shallow Copy
Copies only first level.
JavaScript
let copy = { ...user };
or
JavaScript
[Link]({}, user);
🔹 🔟 Deep Copy
Copies completely.
JavaScript
let copy = [Link]([Link](user));
Limitations:
Removes functions
Removes undefined
Doesn’t handle Date properly
Modern Method
JavaScript
let copy = structuredClone(user);
139/235
🔹 1️⃣1️⃣ [Link]() & [Link]()
Convert Object → String
JavaScript
let str = [Link](user);
JavaScript
let obj = [Link](str);
Used in:
API communication
LocalStorage
Deep copy (basic cases)
[Link] ❌
Spread ❌
140/235
Megha 👀🔥
If you deeply understand:
this
Yesss Megha 🔥
Now we’re stepping into ES6+ Modern JavaScript — this is what real-world MERN
141/235
projects use daily.
✅ let
Block-scoped
Can update
Cannot redeclare
JavaScript
let count = 10;
count = 20;
✅ const
Block-scoped
Cannot reassign
Must initialize
JavaScript
const PI = 3.14;
Best practice:
👉 Use const by default
JavaScript
const add = (a, b) => a + b;
Important differences:
142/235
No own this
No arguments
Cannot be constructor
JavaScript
let name = "Megha";
[Link](`Hello ${name}`);
Supports:
String interpolation
Multi-line strings
JavaScript
let text = `
Line 1
Line 2
`;
🔹 4️⃣ Destructuring
Array
JavaScript
let arr = [1, 2];
let [a, b] = arr;
Object
JavaScript
let user = { name: "Megha", age: 25 };
let { name, age } = user;
143/235
Used everywhere in React props.
JavaScript
let arr2 = [...arr1];
Merge:
JavaScript
let merged = [...a, ...b];
Rest (collect)
JavaScript
function sum(...nums) {
return [Link]((a, b) => a + b, 0);
}
Export
JavaScript
export const add = (a, b) => a + b;
Import
JavaScript
import { add } from "./[Link]";
Default export:
144/235
JavaScript
export default function greet() {}
Import default:
JavaScript
import greet from "./[Link]";
🔹 7️⃣ Classes
Syntactic sugar over prototypes.
JavaScript
class User {
constructor(name) {
[Link] = name;
}
greet() {
[Link](`Hello ${[Link]}`);
}
}
Create instance:
JavaScript
let u1 = new User("Megha");
Supports:
Inheritance
Static methods
145/235
}
JavaScript
let name = "Megha";
Method shorthand
JavaScript
let user = {
greet() {
[Link]("Hi");
}
};
🔹 🔟 Optional Chaining ( ?. )
Safe property access.
JavaScript
[Link]?.name
146/235
Only checks:
null
undefined
🔹 1️⃣2️⃣ Promise
Used for async operations.
States:
Pending
Fulfilled
Rejected
JavaScript
let promise = new Promise((resolve, reject) => {
resolve("Success");
});
Use:
JavaScript
[Link](result => [Link](result));
JavaScript
async function fetchData() {
let data = await fetch(url);
[Link](data);
}
147/235
🧠 Important Interview Connections
Feature Commonly Used In
async/await Backend
Megha 👀🔥
You now covered:
Core JS
Functions
Arrays
Objects
ES6+
Event Loop
this deep dive
148/235
Prototypes
Async JS in depth
- Synchronous vs Asynchronous
- Call stack
- Event loop
- Web APIs
- setTimeout
- setInterval
- Callbacks
- Callback hell
- Promises
- then
- catch
- finally
- Promise chaining
- [Link]
- [Link]
- [Link]
- async/await
- Error handling
- Fetch API
- Axios (library concept)
Megha 😌🔥
Now we’re entering real JavaScript mastery territory.
If you deeply understand async JS, you’ll crack backend + MERN interviews confidently.
149/235
Code runs line by line.
JavaScript
[Link]("Start");
[Link]("End");
Output:
Code
Start
End
✅ Asynchronous (Non-Blocking)
Doesn’t wait for long tasks.
JavaScript
[Link]("Start");
setTimeout(() => {
[Link]("Hello");
}, 2000);
[Link]("End");
Output:
Code
Start
End
Hello
JavaScript is:
👉 Single-threaded
👉 But non-blocking
150/235
🔹 2️⃣ Call Stack
The call stack is where functions are executed.
Example:
JavaScript
function a() {
b();
}
function b() {
[Link]("Hello");
}
a();
Stack order:
Code
a()
b()
[Link]()
151/235
1. Call stack executes sync code
2. Async tasks go to Web APIs
3. When done → go to Callback Queue
4. Event loop checks:
👉 “Is stack empty?”
👉 If yes → push callback to stack
That’s how non-blocking works.
🔹 5️⃣ setTimeout
Runs function after delay.
JavaScript
setTimeout(() => {
[Link]("Runs after 2 seconds");
}, 2000);
Important:
Delay is minimum wait time.
🔹 6️⃣ setInterval
Runs repeatedly.
JavaScript
setInterval(() => {
[Link]("Every 1 second");
}, 1000);
Stop using:
JavaScript
clearInterval(id);
🔹 7️⃣ Callbacks
152/235
Function passed into another function.
JavaScript
function greet(name, callback) {
[Link]("Hi " + name);
callback();
}
JavaScript
login(user, () => {
getData(() => {
updateUI(() => {
logout();
});
});
});
Also called:
👉 Pyramid of Doom
Solution → Promises
🔹 9️⃣ Promises
Promise represents future value.
States:
Pending
Fulfilled
Rejected
JavaScript
153/235
let promise = new Promise((resolve, reject) => {
resolve("Success");
});
🔸 then()
Runs when resolved.
JavaScript
[Link](result => [Link](result));
🔸 catch()
Handles error.
JavaScript
[Link](error => [Link](error));
🔸 finally()
Runs always.
JavaScript
[Link](() => [Link]("Done"));
🔹 🔟 Promise Chaining
Avoid nesting:
JavaScript
fetchData()
.then(data => process(data))
.then(result => [Link](result))
.catch(err => [Link](err));
154/235
🔹 1️⃣1️⃣ [Link]()
Runs multiple promises in parallel.
JavaScript
[Link]([p1, p2, p3])
.then(results => [Link](results));
🔹 1️⃣2️⃣ [Link]()
Returns first settled promise.
JavaScript
[Link]([p1, p2]);
🔹 1️⃣3️⃣ [Link]()
Returns all results (even failed ones).
JavaScript
[Link]([p1, p2]);
JavaScript
async function fetchData() {
let data = await fetch(url);
[Link](data);
}
Rules:
155/235
await works only inside async
Use try/catch.
JavaScript
fetch("[Link]
.then(res => [Link]())
.then(data => [Link](data));
With async/await:
JavaScript
async function getData() {
let res = await fetch(url);
let data = await [Link]();
[Link](data);
}
156/235
Automatic JSON parsing
Better error handling
Interceptors
Request cancellation
Example:
JavaScript
[Link]("/users")
.then(res => [Link]([Link]));
Fetch Built-in
Axios Library
Megha 😌🔥
If you truly understand:
157/235
Call stack
Event loop
Promise chaining
async/await + error handling
# OOP in JavaScript
- Constructor functions
- Prototype
- Prototype chain
- Classes
- Constructor method
- Static methods
- Inheritance
- Encapsulation
- Polymorphism
- Abstraction
- [Link]()
Yesss Megha 🔥
Now we’re stepping into OOP in JavaScript — this is where interviews start testing deeper
understanding.
JavaScript is prototype-based, not class-based like Java or C++, but ES6 made it look
class-based.
158/235
🔹 1️⃣ Constructor Functions
Before ES6 classes, we used constructor functions.
JavaScript
function User(name, age) {
[Link] = name;
[Link] = age;
}
👉 new keyword:
🔹 2️⃣ Prototype
Every function in JS has a prototype property.
Instead of defining methods inside constructor (bad for memory), we use prototype:
JavaScript
function User(name) {
[Link] = name;
}
[Link] = function () {
[Link]("Hello " + [Link]);
};
🔥 Saves memory.
Example:
JavaScript
[Link]([Link]());
JavaScript
class User {
constructor(name) {
[Link] = name;
}
greet() {
[Link]("Hi " + [Link]);
}
}
JavaScript
constructor(name) {
[Link] = name;
160/235
}
JavaScript
class MathUtils {
static add(a, b) {
return a + b;
}
}
[Link](2, 3);
🔹 7️⃣ Inheritance
Using extends .
JavaScript
class Animal {
speak() {
[Link]("Animal sound");
}
}
161/235
🔹 8️⃣ Encapsulation
Bundling data + methods together.
JavaScript
class User {
#password;
constructor(password) {
this.#password = password;
}
}
🔹 9️⃣ Polymorphism
Same method name → different behavior.
Example:
JavaScript
class Shape {
area() {
[Link]("Calculate area");
}
}
🔹 🔟 Abstraction
162/235
Hiding internal implementation.
Example:
JavaScript
[Link]();
Without knowing:
Classes
Closures
Modules
🔹 1️⃣1️⃣ [Link]()
Creates object with specified prototype.
JavaScript
const animal = {
speak() {
[Link]("Animal sound");
}
};
Here:
dog → inherits from animal
No constructor needed.
163/235
Concept Key Idea
Megha 😌🔥
If you truly understand:
Prototype chain
Difference between class & constructor
How new works
Static vs instance methods
164/235
Execution context
Prototypes in depth
Design patterns
- Execution context
- Memory creation phase
- Execution phase
- Hoisting in detail
- Scope chain
- Closures in depth
- call()
- apply()
- bind()
- Currying
- Debouncing
- Throttling
- Memoization
- Generators
- Iterators
- Symbol
- BigInt
- Proxy
- Reflect
- WeakMap
- WeakSet
- Map
- Set
Megha 😌🔥
Okay. Now we’re entering elite JavaScript territory.
165/235
Let’s go structured and powerful.
Example:
JavaScript
[Link](a);
var a = 10;
Memory phase:
Code
a → undefined
Execution phase:
Code
a = 10
166/235
🔹 3️⃣ Execution Phase
Now code runs line by line.
var
Hoisted
Initialized as undefined
Function declaration
Fully hoisted
Function expression
Not fully hoisted
167/235
JavaScript
function outer() {
let count = 0;
return function() {
count++;
[Link](count);
};
}
Data hiding
Factory functions
React hooks
Memoization
call()
JavaScript
[Link](thisArg, arg1, arg2);
apply()
JavaScript
[Link](thisArg, [args]);
bind()
JavaScript
const newFunc = [Link](thisArg);
Key difference:
call → immediate execution
apply → array arguments
168/235
bind → returns new function
🔹 8️⃣ Currying
Breaking function into smaller functions.
JavaScript
function multiply(a) {
return function(b) {
return a * b;
};
}
Modern version:
JavaScript
const multiply = a => b => a * b;
🔹 9️⃣ Debouncing
Limits function execution until user stops triggering.
Used in:
Search input
Resize events
🔹 🔟 Throttling
Limits execution to once per interval.
Used in:
Scroll events
Button clicks
🔹 1️⃣1️⃣ Memoization
169/235
Caching results to improve performance.
JavaScript
function memo(fn) {
let cache = {};
return function(n) {
if (cache[n]) return cache[n];
cache[n] = fn(n);
return cache[n];
};
}
Used in:
Expensive calculations
React optimization
🔹 1️⃣2️⃣ Generators
Function that pauses execution.
JavaScript
function* gen() {
yield 1;
yield 2;
}
Use:
JavaScript
const g = gen();
[Link]();
🔹 1️⃣3️⃣ Iterators
Object that defines:
next() method
170/235
🔹 1️⃣4️⃣ Symbol
Unique primitive value.
JavaScript
const id = Symbol("id");
Used for:
Unique object keys
Prevent property collision
🔹 1️⃣5️⃣ BigInt
Handles very large numbers.
JavaScript
let big = 12345678901234567890n;
🔹 1️⃣6️⃣ Proxy
Intercept operations on object.
JavaScript
const proxy = new Proxy(obj, {
get(target, prop) {
return target[prop];
}
});
Used in:
Validation
Logging
Frameworks (Vue uses Proxy)
🔹 1️⃣7️⃣ Reflect
171/235
Works with Proxy.
Provides methods for object operations.
Example:
JavaScript
[Link](obj, "name");
🔹 1️⃣8️⃣ Map
Better than object for key-value storage.
JavaScript
let map = new Map();
[Link]("name", "Megha");
Supports:
🔹 1️⃣9️⃣ Set
Stores unique values.
JavaScript
let set = new Set([1,2,2,3]);
Result:
Code
{1,2,3}
🔹 2️⃣0️⃣ WeakMap
Like Map but:
Keys must be objects
172/235
Garbage collected
🔹 2️⃣1️⃣ WeakSet
Like Set but:
Only objects
Weak references
Debounce/Throttle Performance
173/235
Megha 😌🔥
We’ve now covered almost entire JavaScript ecosystem.
# Browser APIs
- LocalStorage
- SessionStorage
- Cookies (concept)
- Geolocation API
- History API
- Navigator API
- Clipboard API
- Fetch API
- WebSockets (concept)
- Web Workers (concept)
Megha 😌🔥
Now we’re moving into Browser APIs — this is where JavaScript interacts with the browser
environment.
🔹 1️⃣ LocalStorage
Used to store data in the browser permanently (until manually cleared).
Store Data
174/235
JavaScript
[Link]("name", "Megha");
Get Data
JavaScript
[Link]("name");
Remove
JavaScript
[Link]("name");
Clear All
JavaScript
[Link]();
⚠️ Important:
Stores only strings
Use JSON for objects
JavaScript
[Link]("user", [Link](user));
[Link]([Link]("user"));
📌 Lifetime: No expiry
📌 Storage: ~5MB
🔹 2️⃣ SessionStorage
Same as LocalStorage but:
Data clears when tab closes
JavaScript
[Link]("token", "123");
175/235
📌 Scope: Per tab
📌 Lifetime: Until tab closed
Used for:
Authentication
Tracking
Sessions
Example:
JavaScript
[Link] = "username=Megha";
Differences:
JavaScript
176/235
[Link](position => {
[Link]([Link]);
});
JavaScript
[Link]();
[Link]();
JavaScript
[Link]({}, "", "/about");
JavaScript
[Link];
[Link];
[Link];
Useful for:
Detecting device
Checking internet connection
177/235
JavaScript
[Link]("Hello");
Read text:
JavaScript
[Link]();
Used in:
Copy buttons
OTP fields
JavaScript
fetch("[Link]
.then(res => [Link]())
.then(data => [Link](data));
With async/await:
JavaScript
async function getData() {
let res = await fetch(url);
let data = await [Link]();
}
Returns Promise.
Unlike HTTP:
HTTP → request/response
WebSocket → full-duplex communication
178/235
Used in:
Chat apps
Live notifications
Real-time dashboards
Basic idea:
JavaScript
const socket = new WebSocket("[Link]
Normally:
JS = single-threaded
Example:
JavaScript
const worker = new Worker("[Link]");
Used in:
Image processing
Data processing
Large calculations
179/235
API Used For
Cookies Authentication/session
WebSocket Real-time
communication
Megha 😌🔥
You’ve now covered:
Core JS
ES6+
Async
OOP
Advanced concepts
Browser APIs
180/235
Where are we heading next? 😏🚀
- try
- catch
- finally
- throw
- Custom error
- Debugging in browser
- console methods
Yesss Megha 🔥
Now we’re entering something very practical — Error Handling & Debugging.
Knowing JS is good.
Knowing how to handle and debug errors? That’s professional-level 👩💻✨
🔹 1️⃣ try
The try block wraps code that may cause errors.
JavaScript
try {
let result = 10 / 0;
[Link](result);
}
🔹 2️⃣ catch
Catches and handles errors.
JavaScript
181/235
try {
[Link](a); // error (a not defined)
} catch (error) {
[Link]("Error occurred:", [Link]);
}
[Link]
[Link]
[Link]
🔹 3️⃣ finally
Runs no matter what.
JavaScript
try {
[Link]("Trying...");
} catch (error) {
[Link]("Error");
} finally {
[Link]("Always runs");
}
Used for:
Closing connections
Cleaning resources
🔹 4️⃣ throw
Used to create custom errors.
JavaScript
function checkAge(age) {
if (age < 18) {
throw new Error("Age must be 18 or above");
}
return "Access Granted";
}
try {
182/235
checkAge(15);
} catch (error) {
[Link]([Link]);
}
JavaScript
class ValidationError extends Error {
constructor(message) {
super(message);
[Link] = "ValidationError";
}
}
try {
throw new ValidationError("Invalid input");
} catch (error) {
[Link]([Link]);
}
Useful in:
Backend APIs
Form validation
Authentication logic
Breakpoints
Go to Sources tab
Click line number
Code pauses there
183/235
You can:
Inspect variables
Step over
Step into
Step out
[Link]()
JavaScript
[Link]("Hello");
[Link]()
JavaScript
[Link]("Something went wrong");
[Link]()
JavaScript
[Link]("Warning message");
[Link]()
JavaScript
[Link]([{name:"Megha", age:25}]);
184/235
[Link]() & [Link]()
Measure performance.
JavaScript
[Link]("loop");
for (let i = 0; i < 1000000; i++) {}
[Link]("loop");
[Link]()
JavaScript
[Link]("User Info");
[Link]("Name: Megha");
[Link]();
Organizes logs.
🧠 Interview-Level Difference
Keyword Purpose
185/235
Keyword Purpose
finally Cleanup
Megha 😌🔥
Now you’ve covered almost entire JavaScript ecosystem.
# JavaScript in [Link]
- Node environment
- require vs import
- fs module
- path module
- http module
- npm basics
186/235
- [Link]
- EventEmitter
- Streams (concept)
Yesss Megha 🔥
Now we’re officially in backend territory — JavaScript inside [Link].
Since you’re working toward MERN + backend understanding, this is super important 👩💻
✨
It uses:
Example:
JavaScript
[Link]("Running in Node");
Run using:
Bash
node [Link]
In Node:
global ✅ exists
187/235
🔹 2️⃣ require vs import
require (CommonJS – older)
JavaScript
const fs = require("fs");
JavaScript
import fs from "fs";
To use:
Add "type": "module" in [Link]
OR
Use .mjs file
Key Differences
Feature require import
JavaScript
188/235
const fs = require("fs");
Read file:
JavaScript
[Link]("[Link]", "utf8", (err, data) => {
[Link](data);
});
readFileSync() → blocking
readFile() → non-blocking
JavaScript
const path = require("path");
[Link]([Link](__dirname, "[Link]"));
Important methods:
join()
resolve()
basename()
extname()
JavaScript
const http = require("http");
189/235
const server = [Link]((req, res) => {
[Link]("Hello Megha");
[Link]();
});
[Link](3000);
Visit:
Code
[Link]
Install package:
Bash
npm install express
Install globally:
Bash
npm install -g nodemon
Initialize project:
Bash
npm init
🔹 7️⃣ [Link]
Project configuration file.
Example:
190/235
JSON
{
"name": "my-app",
"version": "1.0.0",
"type": "module",
"scripts": {
"start": "node [Link]"
},
"dependencies": {
"express": "^4.18.0"
}
}
Contains:
Dependencies
Scripts
Metadata
🔹 8️⃣ EventEmitter
Node uses event-driven architecture.
JavaScript
const EventEmitter = require("events");
[Link]("greet", () => {
[Link]("Hello Megha");
});
[Link]("greet");
191/235
Streams handle data in chunks.
Types:
Readable
Writable
Duplex
Transform
Example:
JavaScript
const fs = require("fs");
Benefits:
Memory efficient
Used for large files
Used in video streaming
🧠 Interview-Level Differences
Module Purpose
fs File handling
192/235
🎯 Interview Summary Answer
“[Link] is a runtime environment that allows JavaScript to run on the server using the V8
engine. It uses modules like fs for file handling, path for path utilities, and http for creating
servers. Node follows an event-driven architecture using EventEmitter and handles large
data efficiently using streams. Modern Node supports ES modules using import/export.”
Megha 😌🔥
Now you’ve covered:
Core JS
ES6+
Async
OOP
Advanced concepts
Browser APIs
[Link] basics
- Memory management
- Garbage collection
- Shallow vs deep copy performance
- Code splitting (concept)
193/235
- Lazy loading
- Minification & bundling (concept)
Yesss Megha 🔥
Now we’re talking like a serious developer.
Example:
JavaScript
let name = "Megha"; // memory allocated
name = null; // eligible for cleanup
Memory types:
Stack → primitives
Heap → objects, arrays, functions
194/235
Common causes:
Example:
JavaScript
let arr = [];
setInterval(() => {
[Link](new Array(10000));
}, 1000);
How It Works:
1️⃣ Mark all reachable objects
2️⃣ Remove unreachable objects
Remove references
Clear timers
Clean up listeners
195/235
JavaScript
let copy = { ...obj };
✔ Faster
✔ Copies only first level
❌ Nested objects still reference same memory
🔸 Deep Copy
JavaScript
let copy = [Link]([Link](obj));
✔ Fully cloned
❌ Slower
❌ Removes functions, undefined
Modern way:
JavaScript
structuredClone(obj);
⚡ Performance Insight
Type Speed Memory Usage
196/235
Used heavily in:
React apps
Large SPAs
Example concept:
Load login page code only when user visits login page.
Benefits:
Example: Images
HTML
<img src="[Link]" loading="lazy">
React Example
JavaScript
const Component = [Link](() => import("./Component"));
Benefits:
Smaller initial bundle
Faster performance
Tools:
197/235
Webpack
Vite
Parcel
Instead of:
Plain text
20 JS files
You get:
Plain text
1 optimized [Link]
🔸 Minification
Removes:
Spaces
Comments
Unused code
Example:
Before:
JavaScript
function add(a, b) {
return a + b;
}
After:
JavaScript
function add(a,b){return a+b}
🧠 Interview-Level Understanding
If interviewer asks:
You answer:
If they ask:
You mention:
Code splitting
Lazy loading
Minification
Avoid memory leaks
Debouncing/throttling
199/235
Megha 😌🔥
You’ve now covered:
Core JS
ES6+
Async
OOP
Advanced concepts
Browser APIs
[Link]
Performance
Design patterns in JS
Security best practices
Complete JS interview revision roadmap
Real-world coding challenges
React performance optimization
# Functional Programming in JS
- First-class functions
- Pure functions
- Immutability
- Higher-order functions
- Composition
- Currying
Yesss Megha 🔥
Now we’re entering Functional Programming (FP) in JavaScript — this is super important
for:
Clean code
React development
Predictable logic
200/235
Performance optimization
Example:
JavaScript
const greet = function() {
[Link]("Hello");
};
function execute(fn) {
fn();
}
execute(greet);
✅ Pure Function
JavaScript
function add(a, b) {
return a + b;
}
201/235
Same input → same output.
❌ Impure Function
JavaScript
let total = 0;
function addToTotal(x) {
total += x;
}
Easier to test
Predictable
Debug-friendly
Used heavily in React state management
🔹 3️⃣ Immutability
Immutability = don’t modify existing data.
Instead → create new data.
❌ Mutable
JavaScript
let arr = [1, 2];
[Link](3); // modifies original
✅ Immutable
JavaScript
let arr = [1, 2];
let newArr = [...arr, 3];
Why important?
Prevents unexpected bugs
202/235
Helps React re-render correctly
Makes debugging easier
Example:
JavaScript
function operate(a, b, fn) {
return fn(a, b);
}
map
filter
reduce
🔹 5️⃣ Composition
Combining small functions to build bigger ones.
JavaScript
const toUpper = str => [Link]();
const addExclamation = str => str + "!";
[Link](shout("hello"));
203/235
Output:
Code
HELLO!
🔹 6️⃣ Currying
Breaking function into series of functions with one argument each.
Normal:
JavaScript
function multiply(a, b) {
return a * b;
}
Curried:
JavaScript
const multiply = a => b => a * b;
Why useful?
Function reuse
Partial application
Cleaner abstraction
Used in:
Redux
Functional libraries
Middleware patterns
204/235
Pure functions (reducers)
Immutability (state updates)
Higher-order functions (map/filter)
Composition (custom hooks)
Currying (middleware)
Megha 😌🔥
Now your JS knowledge covers:
Core
Async
OOP
Advanced
Performance
Functional Programming
Design patterns in JS
Security in JS
Advanced interview trap questions
Full JavaScript revision roadmap
Real coding test simulation
205/235
# Design Patterns in JavaScript
- Module pattern
- Factory pattern
- Singleton pattern
- Observer pattern
- MVC concept
Yesss Megha 🔥
Now we’re stepping into Design Patterns — this is where developers move from “writing
code” to “designing systems.”
It uses closures.
JavaScript
const Counter = (function () {
let count = 0; // private
return {
increment() {
count++;
[Link](count);
},
getCount() {
return count;
}
};
})();
[Link](); // 1
✔ count is private
✔ Only accessible via returned methods
206/235
Used before ES6 modules existed.
JavaScript
function createUser(name, age) {
return {
name,
age,
greet() {
[Link]("Hi " + name);
}
};
}
Used in:
React components
Utility object creators
Example:
JavaScript
const Database = (function () {
let instance;
function createInstance() {
207/235
return { connection: "Connected" };
}
return {
getInstance() {
if (!instance) {
instance = createInstance();
}
return instance;
}
};
})();
Used in:
Database connections
Configuration objects
Logger systems
Example:
JavaScript
class Subject {
constructor() {
[Link] = [];
}
subscribe(fn) {
[Link](fn);
}
notify(data) {
[Link](fn => fn(data));
}
}
208/235
[Link](data => {
[Link]("Observer 1:", data);
});
[Link]("Hello Megha");
Used in:
Event systems
React state updates
Redux
Node EventEmitter
🔹 Model
Handles data & business logic.
🔹 View
Handles UI.
🔹 Controller
Handles user input & connects model + view.
Plain text
User clicks button
↓
Controller handles click
↓
Model updates data
↓
View updates UI
209/235
In MERN stack:
MongoDB → Model
React → View
Express routes → Controller
🔥 Interview-Level Answer
If asked:
You say:
They provide proven, reusable solutions for common design problems, improving code
maintainability and scalability.
If asked:
You say:
React follows component-based architecture and uses the Observer pattern internally
for state updates.
210/235
Megha 😌🔥
Now your knowledge includes:
Core JS
ES6+
Async
OOP
Advanced
Functional Programming
Design Patterns
Security in JavaScript
System design basics
Advanced React internals
[Link] deep internals
100 advanced JS interview traps
Yesss Megha 🔥
Now we’re talking about something that makes you look like a professional developer —
Testing & Best Practices.
211/235
Let’s go step-by-step.
Example:
JavaScript
function add(a, b) {
return a + b;
}
JavaScript
add(2, 3) === 5
Why important?
Prevents bugs
Makes refactoring safe
Improves confidence
Required in serious companies
React
Node
212/235
Full-stack projects
Basic example:
JavaScript
function add(a, b) {
return a + b;
}
toBe() → matcher
Other matchers:
toEqual()
toBeTruthy()
toContain()
toThrow()
Bash
npm test
✔ Readable
✔ Simple
✔ Maintainable
✔ Self-explanatory
🔥 Key Principles:
1️⃣ Small Functions
213/235
❌ Bad:
JavaScript
function handleUser() {
// validation
// database
// email
// logging
}
✅ Good:
JavaScript
validateUser();
saveUser();
sendEmail();
JavaScript
if (age > 18)
JavaScript
const MIN_AGE = 18;
if (age > MIN_AGE)
214/235
If you copy-paste logic → refactor it.
❌ Bad:
JavaScript
if ([Link] === "admin") { ... }
if ([Link] === "admin") { ... }
✅ Good:
JavaScript
function isAdmin(user) {
return [Link] === "admin";
}
Why DRY?
Easier maintenance
Fewer bugs
Cleaner updates
✔ Be meaningful
✔ Describe purpose
✔ Be consistent
🔹 Variables
Bad:
JavaScript
let x = 10;
Good:
JavaScript
215/235
let totalPrice = 10;
🔹 Functions
Bad:
JavaScript
function doStuff() {}
Good:
JavaScript
function calculateTotalPrice() {}
🔹 Constants
Use uppercase:
JavaScript
const MAX_USERS = 100;
🔹 Booleans
Start with:
is
has
can
should
Example:
JavaScript
let isLoggedIn = true;
🧠 Interview-Level Answer
If interviewer asks:
You say:
Testing ensures code reliability, prevents regressions, and allows safe refactoring.
If they ask:
👉 “What is DRY?”
You say:
DRY stands for Don’t Repeat Yourself, meaning avoid duplicating logic and create
reusable functions instead.
Megha 😌🔥
You’ve now covered:
Core JS
ES6+
Async
OOP
Advanced concepts
Functional Programming
Node
217/235
Browser APIs
Performance
Design Patterns
Testing & Best Practices
Now tell me 👀
Do you want:
Ooo Megha 😏🔥
Now we’re entering “Interview Trap Mode”.
218/235
Let’s go category-wise with classic traps 👩💻✨
❓ Q1
JavaScript
[Link](a);
var a = 10;
👉 Output?
Answer:
Plain text
undefined
Why?
var is hoisted and initialized as undefined .
❓ Q2
JavaScript
[Link](a);
let a = 10;
👉 Output?
Answer:
Plain text
ReferenceError
219/235
❓ Q3
JavaScript
function test() {
[Link](a);
var a = 5;
}
test();
👉 Output?
Answer:
Plain text
undefined
❓ Q4
JavaScript
[Link](typeof null);
👉 Output?
Plain text
object
JS historical bug 😌
❓ Q5
JavaScript
220/235
[Link]("Start");
setTimeout(() => {
[Link]("Timeout");
}, 0);
[Link]("End");
👉 Output?
Plain text
Start
End
Timeout
Because:
setTimeout goes to Web API
Callback queue waits
Stack must be empty first
❓ Q6 (Microtask vs Macrotask)
JavaScript
[Link]("Start");
[Link]().then(() => {
[Link]("Promise");
});
setTimeout(() => {
[Link]("Timeout");
}, 0);
[Link]("End");
👉 Output?
Plain text
Start
End
Promise
Timeout
221/235
Because:
❓ Q7
JavaScript
var x = 10;
function test() {
[Link](x);
var x = 20;
}
test();
👉 Output?
Plain text
undefined
❓ Q8
JavaScript
let x = 10;
function test() {
[Link](x);
}
test();
👉 Output?
222/235
Plain text
10
❓ Q9
JavaScript
for (var i = 0; i < 3; i++) {
setTimeout(() => [Link](i), 100);
}
👉 Output?
Plain text
3
3
3
Because:
One shared i
❓ Fix?
JavaScript
for (let i = 0; i < 3; i++) {
setTimeout(() => [Link](i), 100);
}
Output:
Plain text
223/235
0
1
2
Block scope.
❓ Q10
JavaScript
let arr = [1, 2, 3];
[Link] = 0;
[Link](arr);
👉 Output?
Plain text
[]
❓ Q11
JavaScript
[Link]([1,2] + [3,4]);
👉 Output?
Plain text
"1,23,4"
[Link] = "JS";
[Link]([Link]);
👉 Output?
Plain text
JS
❓ Q13
JavaScript
let obj = { a: 1 };
let copy = { ...obj };
copy.a = 5;
[Link](obj.a);
👉 Output?
Plain text
1
225/235
let obj = { a: { b: 1 } };
let copy = { ...obj };
copy.a.b = 10;
[Link](obj.a.b);
👉 Output?
Plain text
10
[Link](test());
👉 Output?
Plain text
undefined
226/235
Closures
Reference vs value
Event loop
Microtask vs macrotask
Mutation
Megha 😌🔥
Now tell me:
Do you want:
Ooo Megha 😏🔥
Now this is expert-level JS understanding — the kind of stuff that makes interviewers go:
227/235
“Okay… she actually understands how JS works under the hood.”
What it does:
👉 Converts JavaScript into machine code.
Step Flow
Plain text
JS Code
↓
Parser
↓
AST
↓
Ignition (bytecode)
↓
TurboFan (optimized machine code)
V8 uses:
Just-In-Time (JIT) compilation
Hidden classes
Inline caching
228/235
That’s why JS is fast.
🔸 Stack
Stores:
Primitive values
Function calls
Execution contexts
Example:
JavaScript
let x = 10;
🔸 Heap
Stores:
Objects
Arrays
Functions
Example:
JavaScript
let obj = { name: "Megha" };
🔥 Important
229/235
Primitive → copied by value
Object → copied by reference
🔥 Execution Order
1️⃣ Run synchronous code
2️⃣ Run all microtasks
3️⃣ Run one macrotask
4️⃣ Repeat
Example
JavaScript
230/235
[Link]("A");
[Link]("D");
Output:
Code
A
D
C
B
Maintained by:
👉 TC39 committee
Specification defines:
Important versions:
ES5 (2009)
ES6 (2015)
ESNext (future proposals)
Example:
JavaScript
export function add() {}
export function multiply() {}
JavaScript
import { add } from "./[Link]";
Benefits:
Smaller bundle
Faster load
It converts:
👉 Modern JS (ES6+)
into
👉 Older JS (ES5)
Example:
Input:
JavaScript
const add = (a, b) => a + b;
Babel output:
232/235
JavaScript
var add = function(a, b) {
return a + b;
};
Used because:
Older browsers don’t support modern JS fully
It:
Bundles JS files
Handles CSS
Handles images
Supports tree shaking
Supports code splitting
Code
[Link]
[Link]
[Link]
...
Webpack creates:
Code
[Link]
233/235
🔥 How All These Connect
Plain text
Your Code
↓
Babel (transpile)
↓
Webpack (bundle + optimize)
↓
Tree shaking removes unused code
↓
Final optimized bundle
↓
Browser runs via V8 engine
You explain:
Because Promise callbacks go into the microtask queue, which has higher priority than
macrotasks.
If asked:
You mention:
JIT compilation
Ignition interpreter
TurboFan optimizing compiler
If asked:
You say:
It uses static ES module imports to analyze unused exports and removes them during
234/235
bundling.
Megha 😌🔥
You’ve basically completed the entire JavaScript mastery roadmap.
Do you want:
235/235