JavaScript Notes
Complete JavaScript interview guide 2026. Covers 50 most asked questions on closures, hoisting, promises, prototypes, async/await, event loop, DOM, and ES6+ features.
Your complete JavaScript interview preparation guide. These are the most frequently asked questions — from fresher-level to senior developer interviews at top companies.
Section 1: JavaScript Fundamentals
Q1: What is JavaScript? How is it different from Java?
Answer:
- JavaScript is a dynamic, interpreted, prototype-based scripting language primarily for web.
- Java is statically typed, compiled to bytecode, class-based OOP language.
- No actual relation beyond similar syntax style.
| Feature | JavaScript | Java |
|---|---|---|
| Typing | Dynamic | Static |
| Execution | Interpreted/JIT | Compiled (JVM) |
| OOP | Prototype-based | Class-based |
| Threading | Single-threaded | Multi-threaded |
| Use case | Web frontend/backend | Enterprise/Android |
Q2: What are the data types in JavaScript?
Answer: JavaScript has 8 data types:
Primitive (7):
typeof 42 // "number"
typeof "hello" // "string"
typeof true // "boolean"
typeof undefined // "undefined"
typeof null // "object" ← bug! (primitive)
typeof Symbol() // "symbol"
typeof 9007199254740993n // "bigint"Non-Primitive (1):
typeof {} // "object"
typeof [] // "object"
typeof function(){} // "function" (subtype of object)"number" "string" "boolean" "undefined" "object" "symbol" "bigint" "object" "object" "function"
Q3: What is the difference between == and ===?
console.log(1 == "1"); // true (type coercion)
console.log(1 === "1"); // false (no coercion)
console.log(null == undefined); // true
console.log(null === undefined); // false
console.log(NaN == NaN); // false
console.log(NaN === NaN); // falsetrue false true false false false
Rule: Always use === unless you have a specific reason for ==.
Q4: var vs let vs const
// var: function-scoped, hoisted as undefined, re-declarable
var x = 1;
var x = 2; // OK
// let: block-scoped, hoisted into TDZ, not re-declarable
let y = 1;
// let y = 2; // SyntaxError
// const: block-scoped, must be initialized, not reassignable
const z = 1;
// z = 2; // TypeError| Feature | var | let | const |
|---|---|---|---|
| Scope | Function | Block | Block |
| Hoisting | undefined | TDZ | TDZ |
| Re-declare | ✅ | ❌ | ❌ |
| Re-assign | ✅ | ✅ | ❌ |
| window prop | ✅ | ❌ | ❌ |
Q5: What is undefined vs null?
let a; // undefined — variable declared but not assigned
let b = null; // null — explicitly "no value"
console.log(typeof undefined); // "undefined"
console.log(typeof null); // "object" (JS bug)
console.log(null == undefined); // true
console.log(null === undefined); // false"undefined" "object" true false
Q6: What is NaN? How to check for it?
console.log(NaN === NaN); // false — NaN is not equal to itself!
console.log(typeof NaN); // "number"
console.log(isNaN("hello")); // true (coerces first — use carefully)
console.log(Number.isNaN("hello")); // false (strict — doesn't coerce)
console.log(Number.isNaN(NaN)); // truefalse "number" true false true
Best Practice: Always use Number.isNaN() over isNaN().
Section 2: Functions
Q7: What is a closure?
Answer: A closure is a function that retains access to its lexical scope even after the outer function has returned.
3
Q8: What is hoisting?
console.log(x); // undefined (var hoisted)
var x = 5;
greet(); // "Hello!" (function hoisted fully)
function greet() { console.log("Hello!"); }
// console.log(y); // ReferenceError (TDZ — let/const)
let y = 10;undefined Hello!
Q9: Arrow functions vs Regular functions
JS undefined
Differences:
| Feature | Regular | Arrow |
|---|---|---|
this | Dynamic | Lexical |
arguments | Yes | No |
new | Yes | No (not constructor) |
| Syntax | Verbose | Concise |
Q10: What are higher-order functions?
[2, 4, 6, 8, 10] [2, 4] 15
Q11: What is this in JavaScript?
WoHoTech undefined
Q12: call, apply, bind
Priya is Developer at Google Priya is Designer at Apple Priya is Engineer at Microsoft
Section 3: Scope & Prototype
Q13: What is the scope chain?
const global = "G";
function outer() {
const a = "A";
function inner() {
const b = "B";
console.log(b, a, global); // inner → outer → global
}
inner();
}
outer();B A G
Q14: What is the prototype chain?
function Animal(name) {
this.name = name;
}
Animal.prototype.speak = function() {
return `${this.name} makes a sound`;
};
const dog = new Animal("Rex");
console.log(dog.speak());
console.log(dog.hasOwnProperty("name")); // true
console.log(dog.hasOwnProperty("speak")); // false (on prototype)Rex makes a sound true false
Q15: What does the new keyword do?
Alice true
Section 4: ES6+ Features
Q16: Destructuring
1 2 [3, 4, 5] Raj 25 Delhi
Q17: Spread vs Rest
10
Q18: Template Literals
Hello <b>JavaScript</b>! Welcome to <b>2026</b>.
Q19: Optional Chaining & Nullish Coalescing
const user = {
profile: {
address: null
}
};
// Without optional chaining: throws error
// user.profile.address.city
// With optional chaining
console.log(user?.profile?.address?.city); // undefined
console.log(user?.profile?.phone?.number); // undefined
console.log(user?.settings?.theme ?? "light"); // "light"undefined undefined light
Q20: Map vs Object vs Set vs Array
| Feature | Map | Object | Set | Array |
|---|---|---|---|---|
| Key types | Any | String/Symbol | — | Index |
| Order | Insertion | Not guaranteed | Insertion | Index |
| Size | .size | Object.keys().length | .size | .length |
| Iteration | Easy | Need Object.entries | Easy | Easy |
| Use when | Key-value, any key | Record/config | Unique values | Ordered list |
[1, 2, 3]
Section 5: Async JavaScript
Q21: What is a Promise?
Done!
Q22: async/await syntax
async function loadUser(id) {
try {
const user = await getUser(id); // awaits Promise
const posts = await getPosts(user.id);
return { user, posts };
} catch (err) {
console.error("Failed:", err.message);
}
}Q23: Event Loop — What is the output?
1 4 3 2
Section 6: OOP in JavaScript
Q24: Class Syntax
class Animal {
#sound; // private field
constructor(name, sound) {
this.name = name;
this.#sound = sound;
}
speak() {
return `${this.name}: ${this.#sound}!`;
}
static create(name, sound) {
return new Animal(name, sound);
}
}
class Dog extends Animal {
constructor(name) {
super(name, "Woof");
this.tricks = [];
}
learn(trick) {
this.tricks.push(trick);
return this;
}
}
const d = new Dog("Rex");
d.learn("sit").learn("stay");
console.log(d.speak());
console.log(d.tricks);Rex: Woof! ["sit", "stay"]
Q25: Inheritance via Prototype
function Shape(color) { this.color = color; }
Shape.prototype.describe = function() {
return `${this.color} shape`;
};
function Circle(color, radius) {
Shape.call(this, color); // inherit properties
this.radius = radius;
}
Circle.prototype = Object.create(Shape.prototype); // inherit methods
Circle.prototype.constructor = Circle;
Circle.prototype.area = function() {
return Math.PI * this.radius ** 2;
};
const c = new Circle("red", 5);
console.log(c.describe());
console.log(c.area().toFixed(2));red shape 78.54
Section 7: Common Interview Traps
Q26: typeof null
console.log(typeof null); // "object" — famous JS bug!"object"
Q27: Floating Point Precision
console.log(0.1 + 0.2); // 0.30000000000000004
console.log(0.1 + 0.2 === 0.3); // false!
// Fix:
console.log(Math.abs(0.1 + 0.2 - 0.3) < Number.EPSILON); // true
console.log((0.1 + 0.2).toFixed(1) === "0.3"); // true0.30000000000000004 false true true
Q28: Implicit Type Coercion
2 1 2 "53" "[object Object]" 0
Q29: Object Reference vs Primitive
let a = 5;
let b = a;
b = 10;
console.log(a); // 5 (primitives copied by value)
let obj1 = { x: 1 };
let obj2 = obj1;
obj2.x = 99;
console.log(obj1.x); // 99 (objects copied by reference)5 99
Q30: Array Methods Chaining
["Carol: 91", "Alice: 85"]
Most Asked Interview Tips 🎯
- Know your data types — especially
typeof null === "object". - Explain closures with a counter example.
- Draw the event loop when explaining async.
- Use const by default — shows modern JS knowledge.
- Mention Edge Cases — null checks, empty arrays, NaN.
- Know HOFs — map, filter, reduce are always asked.
- Prototype chain — draw it out if asked.
thisrules — regular vs arrow in callbacks.
Interview Preparation Checklist
- [ ] Data types and typeof
- [ ] var / let / const differences
- [ ] Hoisting (var, let, function declarations)
- [ ] Closures (definition + 3 use cases)
- [ ] Scope chain (lexical scoping)
- [ ] Prototype and prototype chain
- [ ]
thiskeyword and its 4 rules - [ ] call, apply, bind
- [ ] Event loop (sync → microtask → macrotask)
- [ ] Promises (states, .all, .race, .allSettled, .any)
- [ ] async/await (+ error handling)
- [ ] ES6: destructuring, spread/rest, template literals
- [ ] map, filter, reduce
- [ ] Shallow vs deep copy
- [ ] Type coercion (
==traps) - [ ] Classes and inheritance
Exam Focus
Revise definitions, diagrams, examples, and short-answer points for Top 50 JavaScript Interview Questions & Answers 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, interview, top 50 javascript interview questions & answers 2026
Related JavaScript Master Course Topics