Junior — 25 questions
These are asked in nearly every first-round JavaScript interview and in most screening calls. Answer each out loud before opening it; an answer you can only recognise is not one you can give under pressure.
JuniorWhat is the difference between let, const and var?
let and const are block-scoped and cannot be used before their declaration; const also cannot be reassigned (its object contents can still change). var is function-scoped, hoisted as undefined, and can be redeclared. Modern code: const by default, let when it changes, never var.
JuniorWhat is the difference between == and ===?
=== compares type and value with no conversion. == converts first, which gives surprises like 0 == "" and [] == false being true. Always use ===; the one idiomatic == is x == null to catch both null and undefined.
JuniorWhat are the primitive types?
string, number, boolean, undefined, null, bigint and symbol. Everything else — arrays, functions, dates, Maps — is an object. Primitives are immutable and compared by value; objects are compared by reference.
JuniorWhat does typeof null return, and why?
"object" — a bug from the first implementation in 1995 that cannot be fixed because existing code depends on it. Check for null with x === null, and for "null or undefined" with x == null.
JuniorWhat is the difference between null and undefined?
undefined means "no value has been assigned" — what you get from a missing property, an unassigned variable or a function without return. null is a value you assign deliberately to mean "empty". JSON.stringify keeps null and drops undefined.
JuniorWhat is a truthy or falsy value?
In a boolean context, exactly eight values are falsy: false, 0, -0, 0n, "", null, undefined, NaN. Everything else is truthy — including "0", "false", [] and {}.
JuniorWhat does "5" + 3 give, and "5" - 3?
"53" and 2. + concatenates if either side is a string; every other arithmetic operator converts to numbers. Convert explicitly with Number() to avoid relying on it.
JuniorWhat is an arrow function and how does it differ from a regular function?
A shorter syntax (x => x * 2) with two real differences: it has no own this (it uses the surrounding scope's), and no arguments object; it also cannot be used with new. Use arrows for callbacks; use methods or declarations where this matters.
JuniorWhat is hoisting?
Declarations are processed before code runs. Function declarations are fully hoisted (callable above their line); var is hoisted as undefined; let/const are hoisted but in the temporal dead zone until their line, so using them early throws a ReferenceError.
JuniorWhat is a closure?
A function that remembers the variables of the scope where it was created, even after that scope has returned. A counter factory returning () => ++count is the classic example. Closures capture variables, not values — the var-in-a-loop bug shows the difference.
JuniorWhat is the difference between map, filter, reduce and forEach?
map returns a new array of transformed items; filter a new array of the items that pass; reduce collapses to one value; forEach returns undefined and exists for side effects. None of them mutate the original.
JuniorHow do you copy an array or object?
Shallow: [...arr], arr.slice(), { ...obj }, Object.assign({}, obj) — nested objects are still shared. Deep: structuredClone(obj) (not functions). b = a is not a copy; it is a second name for the same object.
JuniorWhat does [10, 9, 1].sort() return?
[1, 10, 9]: the default sort converts to strings and compares character by character. Pass a comparator for numbers: sort((a, b) => a - b).
JuniorWhat is JSON and how do you use it in JavaScript?
A text format for data: objects, arrays, strings, numbers, booleans and null, with double-quoted keys. JSON.stringify(value) produces it; JSON.parse(text) reads it and throws a SyntaxError on bad input, so wrap it in try/catch when the text is untrusted.
JuniorWhat is the DOM?
The browser's tree of objects representing the page. JavaScript reads and changes it through document: querySelector to find elements, properties like textContent to change them, addEventListener to react to the user. Frameworks are abstractions over exactly these calls.
JuniorWhat is event bubbling?
After an event fires on an element it travels up through its ancestors, triggering their listeners too. That is what makes delegation work — one listener on a list handles clicks on any item, including ones added later. stopPropagation() halts it.
JuniorWhat is a Promise?
An object representing a value that will be available later: pending, then fulfilled with a value or rejected with an error, exactly once. You attach handlers with .then/.catch/.finally, or use await. Chaining .then keeps async steps flat instead of nested callbacks.
JuniorWhat does async/await do?
An async function always returns a promise; inside it, await pauses that function until a promise settles and gives you its value — or throws its rejection, so ordinary try/catch works. It is syntax over promises, not a different mechanism.
JuniorWhat is the difference between setTimeout(fn, 0) and calling fn()?
fn() runs now, synchronously. setTimeout(fn, 0) queues it as a macrotask: it runs after the current code finishes and after all pending microtasks (promise callbacks). "0 ms" means "as soon as the event loop gets to it", not immediately.
JuniorWhat is NaN and how do you check for it?
"Not a Number" — the result of an invalid numeric operation (Number("abc"), 0 / 0). It is the only value not equal to itself, so x === NaN is always false; use Number.isNaN(x). It is contagious: any arithmetic with NaN gives NaN.
JuniorWhy is 0.1 + 0.2 !== 0.3?
Numbers are IEEE-754 binary floats and 0.1, 0.2 and 0.3 cannot be represented exactly, so the sum is 0.30000000000000004. Compare with a tolerance (Math.abs(a - b) < Number.EPSILON), and never do money in floats — use integer cents.
JuniorWhat is template literal syntax?
Strings in backticks that can span lines and embed expressions with ${…}: `Hello, ${user.name}!`. It replaces string concatenation with + and is the normal way to build strings.
JuniorWhat is destructuring?
Pulling values out of arrays or objects into variables in one statement: const { name, age = 0 } = user, const [first, ...rest] = items. It works in function parameters too and supports defaults, renaming and nesting.
JuniorWhat is the spread operator?
... expands an iterable or object in place: copying ([...arr], { ...obj }), merging ({ ...defaults, ...options }), passing an array as arguments (Math.max(...nums)). As a parameter it is "rest": gather the remaining arguments into an array.
JuniorWhat is the difference between a module and a script?
A module (<script type="module">, or .mjs / "type": "module" in Node) has its own scope, is strict mode, can import and export, and runs once no matter how many files import it. A classic script shares the global scope. New code is modules.
