Beginner JavaScript interview questions
Q1 Beginner ArrayBuffer, TypedArrays & Binary Data
Short answer
An ArrayBuffer is a fixed-length, raw binary data buffer in memory. It has no way to read or write data directly — you need a "view" like a TypedArray or DataView layered on top of it to interpret the bytes as numbers.
Full answer with examples Q2 Beginner Arrays & Array Methods
Short answer
map() returns a new array built from the return value of the callback for each element; forEach() only runs the callback for its side effects and always returns undefined.
Full answer with examples Q3 Beginner Async Iterators & Streams
Short answer
An async iterator is an object with a next() method that returns a Promise resolving to {value, done}, letting you iterate over values that arrive asynchronously over time, like chunks from a network stream.
Full answer with examples Q4 Beginner Browser Storage & Web APIs
Short answer
localStorage persists data with no expiration until explicitly cleared, and is shared across all tabs/windows for the same origin. sessionStorage only lasts for the lifetime of a single tab and is cleared when that tab closes.
Full answer with examples Q5 Beginner Classes & Class Syntax
Short answer
A class is syntactic sugar over JavaScript's existing prototype-based inheritance. It doesn't add a new object model — under the hood, methods still live on the prototype object, just written with cleaner syntax.
Full answer with examples Q6 Beginner Date, Time & Internationalization (Intl API)
Short answer
new Date() with no arguments creates a Date object set to the current date and time, based on the system clock, represented internally as milliseconds since the Unix epoch (Jan 1, 1970 UTC).
Full answer with examples Q7 Beginner Debugging, Testing & Tooling
Short answer
Insert a debugger statement in your code, or click in the gutter of the Sources panel to set a breakpoint. When execution reaches that line, DevTools pauses so you can inspect variables and step through code.
Full answer with examples Q8 Beginner Design Patterns in JavaScript
Short answer
The Module pattern uses a function closure (or an ES module) to keep internal variables private and expose only a controlled public API, preventing external code from directly manipulating internal state.
Full answer with examples Q9 Beginner Destructuring, Spread & Rest
Short answer
Array destructuring pulls values out by position into named variables using square-bracket syntax on the left side of an assignment.
Full answer with examples Q10 Beginner DOM & Events
Short answer
Event bubbling means an event fired on an element propagates upward through its ancestors in the DOM tree, triggering any matching event listeners on parents after the target element's own listeners run.
Full answer with examples Q11 Beginner Error Handling
Short answer
Code inside try runs normally; if it throws an error, execution immediately jumps to the catch block instead of crashing the whole program, letting you handle the error gracefully.
Full answer with examples Q12 Beginner ES Modules
Short answer
A module can have any number of named exports (imported with matching names in curly braces), but at most one default export (imported with any name you choose, no braces required).
Full answer with examples Q13 Beginner Event Loop & Concurrency
Short answer
Yes, JavaScript runs on a single main thread, executing one operation at a time. It achieves the appearance of doing multiple things at once through asynchronous callbacks, Promises, and the event loop — not through true parallel execution on that thread.
Full answer with examples Q14 Beginner Functional Programming
Short answer
A pure function always returns the same output for the same input and produces no observable side effects (no mutating external state, no I/O), which makes it predictable, testable, and easy to reason about in isolation.
Full answer with examples Q15 Beginner Iterators & Generators
Short answer
An object is iterable if it implements the Symbol.iterator method, which returns an iterator object with a next() method. This is what powers for...of loops, spread syntax, and destructuring on that object.
Full answer with examples Q16 Beginner JSON & Data Serialization
Short answer
JSON.stringify() serializes a JavaScript value into a JSON-formatted string, converting objects, arrays, strings, numbers, booleans, and null into their JSON text representation.
Full answer with examples Q17 Beginner Map, Set, WeakMap & WeakSet
Short answer
A Map allows keys of ANY type (objects, functions, even NaN), preserves insertion order reliably, has a .size property, and doesn't come with inherited prototype properties that could collide with your keys — plain objects only reliably support string/Symbol keys.
Full answer with examples Q18 Beginner Memory Management & Garbage Collection
Short answer
JavaScript uses automatic garbage collection: an object's memory is reclaimed once it becomes unreachable — meaning no live reference chain from the global scope, active call stack, or closures leads to it anymore. You never manually free memory like in C.
Full answer with examples Q19 Beginner Networking: Fetch, XHR, WebSockets & CORS
Short answer
fetch(url) returns a Promise that resolves to a Response object once headers arrive; you then call .json() (or .text(), etc.) — itself also returning a Promise — to read and parse the actual body.
Full answer with examples Q20 Beginner Numbers, Math & BigInt
Short answer
JavaScript numbers use the IEEE 754 double-precision floating-point format, which can't represent most decimal fractions exactly in binary — this is a property of floating-point math shared by nearly all programming languages, not a JavaScript-specific bug.
Full answer with examples Q21 Beginner ArrayBuffer, TypedArrays & Binary Data
Short answer
A TypedArray (like Int32Array, Uint8Array, Float64Array) is a view that lets you read and write numeric values of a specific type directly into an ArrayBuffer's memory, without copying data.
Full answer with examples Q22 Beginner Arrays & Array Methods
Short answer
filter() creates a new array containing only the elements for which the callback returns a truthy value; it doesn't mutate the original array.
Full answer with examples Q23 Beginner Async Iterators & Streams
Short answer
Use a for-await-of loop, which automatically awaits each next() call and unwraps the resolved value, pausing the loop until each item is ready.
Full answer with examples Q24 Beginner Browser Storage & Web APIs
Short answer
localStorage's API only accepts and returns strings. To store objects or arrays, serialize them with JSON.stringify() before saving and JSON.parse() them back out after reading.
Full answer with examples Q25 Beginner Classes & Class Syntax
Short answer
constructor() runs automatically when you call new ClassName(...), initializing instance properties. A class can have at most one constructor.
Full answer with examples Q26 Beginner Date, Time & Internationalization (Intl API)
Short answer
Date.parse() (and new Date(string)) behavior for non-ISO formats is implementation-defined, so the same string can parse differently across browsers. Only the ISO 8601 format (e.g. '2026-08-08') is guaranteed to parse consistently.
Full answer with examples Q27 Beginner Debugging, Testing & Tooling
Short answer
console.table() renders an array of objects as a formatted table in the console, making it much easier to scan rows and columns than reading nested console.log() output.
Full answer with examples Q28 Beginner Design Patterns in JavaScript
Short answer
Singleton ensures only one instance of an object exists across the whole application, typically by exporting a single already-created instance from a module — since ES modules are cached, importing it anywhere returns the same instance.
Full answer with examples Q29 Beginner Destructuring, Spread & Rest
Short answer
Object destructuring pulls named properties into variables using curly-brace syntax; the variable names must match the property names unless you rename them.
Full answer with examples Q30 Beginner DOM & Events
Short answer
It cancels the browser's default action for that event — like following a link's href, submitting a form, or checking a checkbox — while still allowing the event to bubble unless you also stop propagation.
Full answer with examples Q31 Beginner Error Handling
Short answer
finally always runs after try/catch, whether or not an error was thrown or caught, and even if the try block returns early — making it ideal for cleanup code that must always execute.
Full answer with examples Q32 Beginner ES Modules
Short answer
Use import * as name from '...' to collect all of a module's named exports into a single object, accessed as name.exportedThing.
Full answer with examples Q33 Beginner Event Loop & Concurrency
Short answer
The call stack tracks which function is currently executing and what called it, growing with each function call and shrinking as functions return — a 'stack overflow' happens when it grows too deep, usually from unbounded recursion.
Full answer with examples Q34 Beginner Functional Programming
Short answer
Immutability means not modifying data after it's created — instead, you produce new data structures with the desired changes. This avoids bugs from shared mutable state and makes it easier to track how and when data changes.
Full answer with examples Q35 Beginner Iterators & Generators
Short answer
Add an asterisk after 'function' to make it a generator; calling it doesn't run the body immediately but returns an iterator, and each yield pauses execution, resuming from that point on the next next() call.
Full answer with examples Q36 Beginner JSON & Data Serialization
Short answer
JSON.parse() parses a JSON-formatted string and returns the corresponding JavaScript value (object, array, string, number, etc.); it throws a SyntaxError if the string isn't valid JSON.
Full answer with examples Q37 Beginner Map, Set, WeakMap & WeakSet
Short answer
A Set only stores unique values — adding a duplicate is a no-op — and lookups with .has() are much faster (O(1) on average) than an array's .includes() (O(n)).
Full answer with examples Q38 Beginner Memory Management & Garbage Collection
Short answer
A memory leak happens when objects remain reachable (and therefore never collected) even though the program logically no longer needs them — typically because a lingering reference (a global variable, a forgotten event listener, or a closure) accidentally keeps them alive.
Full answer with examples Q39 Beginner Networking: Fetch, XHR, WebSockets & CORS
Short answer
Pass an options object as the second argument specifying method: 'POST', a Content-Type header, and a JSON.stringify()'d body — fetch doesn't set the Content-Type header automatically for you.
Full answer with examples Q40 Beginner Numbers, Math & BigInt
Short answer
Number.isInteger(x) returns true only if x is a number with no fractional part (e.g. 5, but not 5.5 or '5'); typeof would just say 'number' for both integers and decimals, without distinguishing them.
Full answer with examples Q41 Beginner ArrayBuffer, TypedArrays & Binary Data
Short answer
Int8Array uses 1 byte per element, Int16Array uses 2, Float64Array uses 8. JS also has Uint8Array, Uint16Array, Int32Array, Uint32Array, Float32Array, and BigInt64Array/BigUint64Array for 64-bit integers.
Full answer with examples Q42 Beginner Arrays & Array Methods
Short answer
reduce() runs a callback that accumulates a single value across the array; its callback arguments are (accumulator, currentValue, index, array), plus an optional initial value for the accumulator.
Full answer with examples Q43 Beginner Classes & Class Syntax
Short answer
extends sets up prototype-based inheritance between classes, and super() inside the subclass's constructor calls the parent class's constructor to initialize inherited state before adding subclass-specific properties.
Full answer with examples Q44 Beginner Debugging, Testing & Tooling
Short answer
A unit test verifies that a single, isolated piece of code (usually a function) behaves correctly for given inputs. A good unit test is fast, deterministic, tests one behavior at a time, and doesn't depend on external systems like a real database or network.
Full answer with examples Q45 Beginner Destructuring, Spread & Rest
Short answer
Spread expands an iterable's elements in place, commonly used to copy an array or merge multiple arrays into a new one without mutating the originals.
Full answer with examples Q46 Beginner DOM & Events
Short answer
Use document.querySelector() (or similar) to find the element, then set its textContent property to update the text safely without interpreting it as HTML.
Full answer with examples