JavaScript Notes
Complete JavaScript quick revision notes covering all important concepts for interviews and exams. Rapid-fire key concepts with code examples and outputs for last-minute preparation.
Last-minute revision guide covering ALL important JavaScript concepts. Short explanations + code + output. Perfect for interviews & exams.
2. Hoisting
JS moves declarations to the top of their scope during the memory phase. But behavior differs:
| Declaration | Hoisted? | Initial Value | TDZ? |
|---|---|---|---|
var | ✅ | undefined | No |
let / const | ✅ | ❌ Not initialized | Yes |
function declaration | ✅ | Full function body | No |
function expression | ✅ | undefined (var) or TDZ (let) | Depends |
console.log(x); // undefined (var hoisted)
console.log(y); // ReferenceError: Cannot access 'y' before initialization
var x = 10;
let y = 20;
greet(); // "Hello!" (function declaration hoisted fully)
function greet() { console.log("Hello!"); }undefined ReferenceError: Cannot access 'y' before initialization
3. Closures
A closure is a function that remembers variables from its outer (lexical) scope even after the outer function has returned. In simple terms: Closure means the inner function remembers the outer scope.
1 2 3
Use cases: Data privacy, memoization, function factories, setTimeout callbacks.
4. this Keyword — 4 Rules
| Rule | Context | this points to |
|---|---|---|
| 1. Default Binding | Standalone function call | window (non-strict) / undefined (strict) |
| 2. Implicit Binding | Method call obj.fn() | The object before the dot |
| 3. Explicit Binding | call/apply/bind | Whatever you pass |
4. new Binding | new Constructor() | Newly created object |
Arrow functions: Don't have their own this. They inherit from parent lexical scope.
WoHo undefined
5. Prototypes & Inheritance
Every JS object has a hidden [[Prototype]] link (accessible via __proto__). When you access a property not on the object, JS walks up the prototype chain.
function Person(name) {
this.name = name;
}
Person.prototype.greet = function() {
return `Hi, I'm ${this.name}`;
};
const p = new Person("Rahul");
console.log(p.greet()); // "Hi, I'm Rahul"
console.log(p.__proto__ === Person.prototype); // true
console.log(Person.prototype.__proto__ === Object.prototype); // trueHi, I'm Rahul true true
Chain: p → Person.prototype → Object.prototype → null
6. Event Loop
JS is single-threaded but non-blocking thanks to the Event Loop.
Order: Sync code → All Microtasks → One Macrotask → All Microtasks → repeat
1 4 3 2
Explanation: Sync first (1, 4) → Microtask (3) → Macrotask (2)
7. Promises & Async/Await
A Promise represents a future value. States: pending → fulfilled / rejected.
Data loaded! Data loaded!
Key methods: Promise.all() (all must resolve), Promise.race() (first to settle), Promise.allSettled() (wait for all, no short-circuit), Promise.any() (first to resolve).
8. Scope — Global, Function, Block
| Scope | var | let/const |
|---|---|---|
| Global | ✅ | ✅ (but not on window) |
| Function | ✅ Confined | ✅ Confined |
Block {} | ❌ Leaks out | ✅ Confined |
if (true) {
var a = 10;
let b = 20;
const c = 30;
}
console.log(a); // 10 (var leaks out of block)
console.log(b); // ReferenceError (let is block-scoped)10 ReferenceError: b is not defined
Scope Chain: Inner scope → Outer scope → ... → Global scope (lexical/static).
9. == vs ===
==(loose equality): Performs type coercion before comparison.===(strict equality): No coercion, both type and value must match.
console.log(0 == ""); // true (both coerce to 0)
console.log(0 === ""); // false (number vs string)
console.log(null == undefined); // true (special rule)
console.log(null === undefined); // false
console.log(NaN == NaN); // false (NaN is never equal to anything)
console.log(1 == "1"); // true
console.log(1 === "1"); // falsetrue false true false false true false
Rule: Always use === unless you intentionally want coercion.
10. Spread / Rest / Destructuring
Spread (...) — Expands elements
Rest (...) — Collects remaining elements
10
Destructuring — Extract values cleanly
10 20 [30, 40] Amit 25
11. map vs filter vs reduce
doubled: [2, 4, 6, 8, 10] evens: [2, 4] total: 15
Remember: map transforms, filter selects, reduce accumulates.
12. Event Bubbling & Delegation
Bubbling: Event triggers on target, then bubbles UP through ancestors (child → parent → grandparent).
Capturing: Event goes DOWN from root to target (rarely used).
Event Delegation: Attach ONE listener on parent, handle events from children via event.target. Great for dynamic lists!
Stop bubbling: e.stopPropagation() | Prevent default: e.preventDefault()
13. localStorage vs sessionStorage
| Feature | localStorage | sessionStorage |
|---|---|---|
| Lifetime | Until manually cleared | Until tab/window closes |
| Scope | Same origin (all tabs) | Same origin + same tab |
| Size | ~5-10 MB | ~5-10 MB |
| Survives refresh? | ✅ Yes | ✅ Yes |
| Survives tab close? | ✅ Yes | ❌ No |
// Store
localStorage.setItem("user", JSON.stringify({ name: "Priya" }));
// Retrieve
const user = JSON.parse(localStorage.getItem("user"));
console.log(user.name); // "Priya"
// Remove
localStorage.removeItem("user");
// Clear all
localStorage.clear();Priya
14. call / apply / bind
All three are used for explicit binding of this.
Sita from Delhi, India Sita from Delhi, India Sita from Delhi, India
Mnemonic: Call = Comma, Apply = Array, Bind = returns Bound function.
15. Debounce vs Throttle
Both limit function execution frequency — crucial for performance optimization.
Debounce — Wait until user STOPS, then fire once
Use case: Search input, window resize. Fires after a pause.
Throttle — Fire at most once every X ms (regular intervals)
Use case: Scroll events, button clicks. Ensures steady rate.
Memory Trick: Debounce = "Wait, let everything finish first" | Throttle = "Once every 1 second"
16. 🧠 Common Tricky Output Questions
Q1: var in loop with setTimeout
Exam Focus
Revise definitions, diagrams, examples, and short-answer points for JavaScript Quick Revision Notes — Interview Prep in 30 Minutes 2026.
Interview Use
Prepare one clear explanation, one practical example, and one common mistake for this JavaScript Master Course topic.
Search Terms
javascript-complete-guide, javascript master course, javascript, complete, guide, notes, quick, revision
Related JavaScript Master Course Topics