📘 Language Basics
1. What's the difference between var, let, and const?
var has function scope and can "leak" out of a block; let and const have block scope, visible only inside their own { } block. let can be reassigned, const can't. var is barely used today.2. What's the difference between == and ===?
== compares values with type coercion ("5" == 5 → true), === compares without coercion, type included ("5" === 5 → false). In practice, === is used almost always.3. What's the difference between null and undefined?
undefined is the default value when a variable hasn't been assigned anything. null is a value a developer sets deliberately, to explicitly say "this is empty".4. What data types exist in JavaScript?
Primitives:
string, number, boolean, undefined, null, symbol, bigint. And one non-primitive type — object (which includes arrays and functions).5. What is hoisting?
A mechanism where variable (
var) and function declarations are moved to the top of their scope before the code runs. let and const are hoisted too, but land in the "temporal dead zone" — you can't access them before their declaration.6. What is a closure?
A function that "remembers" variables from an outer function, even after that outer function has already finished running. A classic example is a counter function that keeps its state between calls.
🗂️ Arrays and Objects
7. How does map differ from forEach?
forEach simply loops over an array and returns nothing. map also loops over an array, but returns a new array with the function's result for each element.8. How do you check whether a variable is an array?
With
Array.isArray(value). The typeof operator returns "object" for an array, so it doesn't work for this.9. How do you copy an object or array?
For a shallow copy — the spread operator:
{...obj} or [...arr]. For a deep copy of nested objects, structuredClone(obj) or JSON.parse(JSON.stringify(obj)) is often used.10. How do you remove an element from an array?
With
splice(index, 1) — this mutates the original array. Or with filter, if you need a new array without mutating the original: arr.filter(item => item !== value).11. What does the reduce method do?
Reduces an array to a single value by looping over each element and accumulating a result. Often used to sum values:
arr.reduce((sum, n) => sum + n, 0).🖥️ DOM and Events
12. How do you select an element on the page?
Most often —
document.querySelector(".class") for one element, and document.querySelectorAll(".class") for several. There's also getElementById.13. What's the difference between addEventListener and onclick?
onclick lets you assign only one handler — a new one replaces the previous one. addEventListener lets you attach as many handlers as you want to the same event, and remove them more flexibly.14. What is event bubbling?
When an event happens on a nested element, it then "bubbles up" through all its parent elements. This enables event delegation — attaching a single handler to a parent instead of many handlers on its children.
15. How do you stop an event's default behavior?
Call
event.preventDefault() inside the handler — for example, to stop a form from reloading the page on submit.⏳ Async
16. What is a Promise?
An object that represents the result of an asynchronous operation — it can be in one of three states:
pending, fulfilled, or rejected.17. How does async/await work?
It's "syntactic sugar" over promises: a function is marked
async, and inside it await "waits" for a promise's result without blocking the rest of the page's code. The code looks and reads like synchronous code.18. What's the difference between setTimeout and setInterval?
setTimeout runs code once after a set delay. setInterval repeats execution at a given interval until it's stopped with clearInterval.💬 General Questions
19. What is this in JavaScript?
A reference to the object a function is executing in the context of. The value of
this depends on how the function was called. Arrow functions don't have their own this — they take it from the surrounding code.20. How do you usually track down a bug in your code?
A good answer: read the error message in the console, place
console.log at suspicious spots or use breakpoints in DevTools, narrow the problem down to a specific line, check variable values at each step.What's next
Getting ready for your first interview?
The JavaScript course covers not just these topics but real practical problems — after it, answering questions like these becomes natural, not memorized.