JavaScript Interview Questions
1.What are the different data types in JavaScript?
Primitive types: String, Number, BigInt, Boolean, Undefined, Symbol, and Null. Non-primitive (reference) type: Object (includes Arrays and Functions).
2.What is the difference between null and undefined?
undefined means a variable is declared but entirely unassigned. null is a deliberate assignment representing 'no value' or an empty state.
3.What is the difference between == and ===?
== only compares values, performing automatic type coercion natively. === strictly compares both the value and the exact data type.
4.What is hoisting in JavaScript?
Hoisting is JS's native behavior of shifting variable and function declarations logically to the top of their scope before code execution starts.
5.What is a closure? Give a real-world example.
A closure natively allows a function to remember and access its outer variables even after the outer function finishes. Example: Generating private module variables.
6.What is the temporal dead zone (TDZ)?
The period specifically between entering a block scope and the exact line where a let or const variable is officially declared, blocking early access.
7.What is the difference between call, apply, and bind?
call explicitly executes a function passing arguments individually. apply strictly requires an array of arguments. bind persistently returns a new locked function.
8.What is 'this' keyword and how is it determined?
this strictly points to the object currently executing the function natively. Arrow functions permanently lock this to their immediate surrounding lexical scope.
9.What are arrow functions and how do they differ from regular functions?
Arrow functions natively lack their own this, arguments, and cannot be used as Constructors. They perfectly handle lexical scoping implicitly.
10.What is destructuring assignment?
It cleanly unpacks values from arrays (const [a, b] = arr) or properties from objects (const { id } = obj) directly into distinct variables natively.
11.What are Promises? How do they work?
Promises represent the eventual completion or failure of an asynchronous operation, actively preventing callback hell by chaining cleanly via .then() and .catch().
12.What is async/await and how does it work?
It acts purely as syntactic sugar over Promises, gracefully allowing asynchronous, non-blocking code to natively read structurally identical to synchronous functions.
13.What is the difference between Promise.all, Promise.race, Promise.allSettled, and Promise.any?
all perfectly awaits everything or fails instantly. race explicitly returns the fastest outcome natively. allSettled waits completely regardless of failures. any reliably returns the first success.
14.What is the difference between map, filter, and reduce?
map structurally transforms every item individually. filter conditionally drops items. reduce powerfully accumulates the entire array down seamlessly into a single value.
15.What does flat() and flatMap() do?
flat() natively collapses nested multi-dimensional arrays cleanly. flatMap() uniquely maps elements first, then inherently flattens the result by one strict level.
16.How do you check if a key exists in an object?
Most accurately by using obj.hasOwnProperty('key') or the modern Object.hasOwn(obj, 'key'). The in operator implicitly checks prototype chains too.
17.What is the JavaScript event loop?
It persistently coordinates asynchronous execution. It inherently checks if the Call Stack is empty, subsequently pushing pending Callbacks strictly from the Task Queue.
18.What is the microtask queue? How does it differ?
The Microtask Queue (handling strictly Promises and MutationObservers) natively holds supreme execution priority, definitively running completely before the standard Macrotask Queue.
19.What is event delegation?
It universally attaches one single smart event listener cleanly to a parent element natively specifically to handle interactions actively originating from dynamic child bubbled events.
20.What is event bubbling and event capturing?
Bubbling inherently flows actions upwards progressively from explicitly clicked child to parent. Capturing uniquely intercepts directly from document root downwards strictly to the target.
21.What is debouncing? Give a use case.
Debouncing essentially prevents a function from firing natively until a specified idle duration completes. Brilliant primarily for structurally throttling auto-save actions or search inputs.
22.What is throttling? How does it differ from debouncing?
Throttling unconditionally forces a function exclusively to execute exactly once per specified time interval continuously natively (like aggressively handling scroll/resize events).
23.How does class syntax work in JavaScript (syntactic sugar)?
ES6 class fundamentally acts completely purely as semantic syntactic sugar wrapped definitively over JS's native invisible prototypical inheritance functions explicitly identically.
24.What is the output of typeof null?
It bizarrely returns 'object'. It is a widely documented historical JS specifically unfixable bug maintained strictly for absolute global backwards compatibility naturally.
25.Why does 0.1 + 0.2 !== 0.3?
Because fundamentally JavaScript structurally relies explicitly entirely on strictly IEEE 754 floating-point natively naturally causing microscopic rounding precision artifacts inherently predictably.