| # | Topic | Key Points |
|---|---|---|
| 1 | Data Type | Primitive (stack) vs Reference (heap) |
| 2 | Variable | var, let, const, hoisting, TDZ |
| 3 | Type Coercion | Implicit vs Explicit conversion |
| 4 | Template Literal | Backticks, interpolation, multi-line |
| 5 | Truthy & Falsy | 8 falsy values, everything else truthy |
| 6 | Destructuring | Array [], Object {}, rest, default, rename |
| 7 | Parameters vs Arguments | Rest ..., default params, arguments object |
| 8 | Optional Chaining | ?. safe access, returns undefined not error |
| 9 | Equality & Comparison | == (coercion) vs === (strict) |
| 10 | Strict Mode | ES5, safer code, no duplicates, restricted keywords |
| 11 | Nullish Coalescing | ?? operator |
| 12 | Ternary Operator | condition ? a : b |
| 13 | Shadowing | Inner scope variable hides outer |
| 14 | Short-circuit Evaluation | && and || early exit |
| 15 | Loop & Iteration | for, for...in, for...of, while, do...while |
| 16 | typeof vs instanceof | Type checking approaches |
- Primitive Data Type (Immutable) — stored in stack
- Number
- String
- Boolean
- undefined
- null
- BigInt
- Symbol
- Reference Data Type (Mutable) — stored in heap
- Object, Array, Function, Date, Map etc.
- Variable holds reference, not actual value
- Reference comparison returns false (different addresses)
constprevents reassigning the reference, not mutating the value
var— redeclaration & reassignment allowed, hoisted with valueundefinedlet— no redeclaration, reassignment allowed, hoisted but in TDZconst— no redeclaration, no reassignment, hoisted but in TDZ
- Implicit — JS auto-converts types
+operator special behavior (string concatenation)-*/convert to number
- Explicit — developer converts manually
Number(),String(),Boolean(),parseInt()- Object to Primitive conversion
- Uses backticks
`for strings - Multi-line string support
- String interpolation:
`${variable}`
- Falsy:
false,0,-0,0n,"",null,undefined,NaN - Everything else is truthy (including
"0","false",[],{})
ES6 feature that allows extracting values from arrays or properties from objects and assigning them into variables in a concise way.
-
Array Destructuring
[]syntax...rest operator — collects remaining elements=default value,skip element
-
Object Destructuring
- Works based on property name, not position
{}syntax- Rename while destructuring:
const { name: userName } = user - Default value support
- Dot notation for access
- Bracket notation when key has special characters:
user["my-age"]
- Parameters — variables defined in the function
- Rest parameter (
...) — takes all arguments into a single array - Default parameter — allows giving a default value to parameters
- Rest parameter (
- Arguments — actual values passed when calling the function
Safely access properties — widely used with API responses. Returns undefined instead of throwing an error if a property is not found.
user?.name // property
user?.address?.city // nested property
user?.sayHello?.() // method
users?.[0] // array/dynamic property==(loose equality) — compares value, may perform type coercion if types differ===(strict equality) — compares both value and type, no type coercion
Introduced in ES5. Makes code safer:
- Prevents deleting non-configurable properties
- Disallows duplicate parameter names in functions
- Reserved words become restricted
?? — provides a default/fallback value when the left-hand side is null or undefined. Unlike ||, it does NOT fall back on other falsy values (0, "", false, NaN).
const username = null;
const result = username ?? "Guest";
console.log(result); // Guest — only null/undefined trigger the fallback
const count = 0;
console.log(count ?? 10); // 0 (?? keeps it, since 0 isn't null/undefined)
console.log(count || 10); // 10 (|| falls back, since 0 is falsy)??— checks onlynull/undefined||— checks any falsy value (0,"",false,null,undefined,NaN)
Shorthand for if...else. Since it takes 3 operands, it's known as the ternary operator.
condition ? valueIfTrue : valueIfFalseCan be chained for multiple conditions:
marks >= 90 ? "A" : marks >= 40 ? "B" : "C"Occurs when a variable declared in an inner scope has the same name as one in an outer scope. The inner scope variable takes precedence and hides (shadows) the outer one within that scope.
let x = 10;
{
let x = 30; // shadows outer x
console.log(x); // 30
}Related concepts:
- Hoisting — variable/function declarations are processed before code execution, during the memory allocation phase
- Scope Chain — the chain of scopes JavaScript searches through when looking up a variable
JavaScript stops evaluating an expression as soon as the final result is already determined — it doesn't always evaluate the entire expression.
&&— if the left side is falsy, the right side is not evaluated||— if the left side is truthy, the right side is not evaluated??=(nullish coalescing) — the right side is evaluated only if the left side isnull/undefined
- For Loop — most commonly used looping mechanism, iterates using
(initialization; condition; increment/decrement)- Flow: initialize → condition → code → increment/decrement → condition → code → ...
- Iterable — a value/object whose elements can be accessed one by one; implements the
Symbol.iteratormethod - For Of Loop — used to iterate over the values of an iterable
- For In Loop — used to iterate over an object/array and get the keys
- While Loop
- Do While Loop
- typeof — identifies the type of a value
typeof "Ashu" // "string" typeof 25 // "number" typeof true // "boolean" typeof undefined // "undefined" typeof {} // "object" typeof [] // "object" typeof function(){} // "function"
- instanceof — checks whether an object is an instance of a particular constructor/class; also used to check the prototype chain relationship
