Javascript Interviews – Top Questions & Answers for Web Developers
JavaScript is a lightweight, interpreted programming language used to build dynamic web pages. It runs in browsers and on servers (via Node.js).
string, number, boolean, null, undefined, symbol, and bigint.
Remember: “SNB-NUBS” – String, Number, Boolean, Null, Undefined, BigInt, Symbol.
undefined: a variable declared but not assigned.null: an intentional empty value.
let a; // undefined
let b = null; // nullIt returns "object" — a long-standing bug in JavaScript.
==checks value equality after type coercion.===checks value and type equality (strict).
NaN means “Not-a-Number”, but it’s actually of type number.
typeof NaN; // "number"Use Number.isNaN(value) instead of isNaN() for accuracy.
Variables and functions are moved to the top of their scope before execution.
console.log(x); // undefined
var x = 5;var: function-scoped, hoisted.let: block-scoped, re-assignable.const: block-scoped, not re-assignable.
String literals enclosed by backticks ` that support interpolation.
const name = "Parth";
console.log(`Hello, ${name}!`);A function assigned to a variable.
const greet = function() { return "Hi"; };A shorter syntax for writing functions, without its own this.
const add = (a, b) => a + b;- Declarations are hoisted.
- Expressions are not.
A closure is when an inner function remembers variables from its outer scope even after the outer function has finished.
function counter() {
let count = 0;
return () => ++count;
}A function passed as an argument to another function to execute later.
- Synchronous: blocks until finished.
- Asynchronous: doesn’t block, uses callbacks, promises, or async/await.
It’s the mechanism that handles asynchronous code execution in JavaScript.
Scope determined by the physical placement of code — nested functions can access outer variables.
Immediately Invoked Function Expression — runs immediately after creation.
(function() {
console.log("Run instantly");
})();A function calling itself until a condition is met.
- Mutating:
push,pop,splice - Non-mutating:
map,filter,reduce,concat
forEach: executes a function for each element (no return).map: returns a new array.
const copy = [...arr];const all = [...arr1, ...arr2];const unique = [...new Set(arr)];- Shallow: copies only one level.
- Deep: copies nested objects too.
Extracting values from arrays/objects easily.
const [x, y] = [1, 2];
const {name, age} = user;const merged = {...obj1, ...obj2};Object.keys(obj).length === 0Safely accessing nested properties.
user?.profile?.email;Allows unpacking values from arrays or properties from objects.
Default values for function parameters.
function greet(name = "Guest") {}Collects all arguments into an array.
function sum(...nums) {}Expands an iterable into elements.
[...arr1, ...arr2];Reusable code blocks using export and import.
Functions that can pause and resume with yield.
A unique and immutable identifier.
A data type for very large integers.
const big = 123456789012345678901234567890n;Custom string processing with functions.
An object that intercepts operations like get/set.
An object that represents the eventual completion (or failure) of an async operation.
Pending → Fulfilled → Rejected.
Syntactic sugar for promises that makes async code look synchronous.
Waits for all promises to resolve.
all: waits for all.race: returns first settled one.
Events propagate from child to parent.
Events propagate from parent to child.
event.stopPropagation();this refers to the context in which a function is executed.
call– calls with arguments.apply– calls with array.bind– returns a new function.
Each object has a hidden [[Prototype]] that forms the prototype chain.
Objects inherit properties from other objects via prototypes.
Classical uses classes; prototypal uses objects directly.
Creates an object with a specific prototype.
Functions that take other functions as arguments or return them.
Breaking a function with multiple arguments into a series of single-argument functions.
Caching the results of expensive function calls.
Delays execution of a function until after a pause.
Ensures a function runs at most once in a time window.
Attaching one event listener to a parent instead of multiple children.
Document Object Model — tree representation of the HTML document.
getElementById, querySelector, querySelectorAll.
innerHTML: parses HTML.textContent: only text.
Custom attributes starting with data- for embedding custom data.
localStorage: persistent.sessionStorage: cleared when tab closes.
Cookies sent with requests; localStorage is client-side only.
Modern interface to make HTTP requests.
JSON.parse() and JSON.stringify().
Cross-Origin Resource Sharing — controls access between different origins.
A background script that enables offline experiences and caching.
Use try...catch.
Syntax errors prevent execution; runtime occurs during execution.
Finding and fixing errors using tools like Chrome DevTools.
Remove event listeners, avoid global variables, and clear timers.
Automatic memory cleanup by removing unused objects.
Blueprint for creating objects.
Special functions for initializing objects.
Allows extending another class and accessing parent methods.
Methods to get and set properties.
Belongs to the class, not the instance.
Shallow checks references; deep compares values recursively.
Data that cannot be modified after creation.
Functions that return the same output for the same input and have no side effects.
JavaScript Object Notation — lightweight format for data exchange.
Code that implements modern features in older browsers.
Converting modern JS to older syntax (e.g., via Babel).
Removing unused code during bundling.
Modules are reusable code units; bundlers (Webpack, Vite) combine them.
Program flow controlled by events.
Read-Eval-Print Loop — an interactive shell for JS.
To safely access nested properties without errors.
Returns the right-hand operand when the left is null or undefined.
value ?? "default";Collections that hold weak object references, not preventing garbage collection.
Loads modules lazily.
import('./module.js');WeakMap keys must be objects and are not iterable.
Microtasks: promises; Macrotasks: setTimeout, I/O.
Encapsulated DOM for web components.
Runs JavaScript in a background thread for parallel processing.
structuredClone() creates a deep copy including nested objects safely.
Because it uses a single main thread and event loop model — concurrency is handled via async mechanisms.