Learn JavaScript
JavaScript has a few famous quirks (coercion, hoisting, this) and a powerful asynchronous model. These quizzes cover both, with code-reading questions rather than trivia.
Covers modern ECMAScript (ES2020+).
What you will practise
- Type coercion and equality
- Scope, closures and hoisting
- Promises, async/await and the event loop
- Array and object idioms
JavaScript lesson
A short introduction to the ideas behind the quizzes, before you start practising.
JavaScript runs in every browser and, via Node.js, on servers too. Its reputation for quirks mostly comes from three areas: how it converts types, how variable scope works, and how asynchronous code actually executes.
Key concepts
let, const and var
`let` and `const` are block-scoped and were introduced to replace the older, function-scoped `var`. `const` prevents reassigning the variable itself, not mutating an object or array it points to.
const user = { name: "Asha" };
user.name = "Ravi"; // allowed: the object is mutated
// user = {}; // not allowed: re-assigning a constEquality: == vs ===
`==` compares after converting both sides to a common type, which produces surprising results. `===` compares type and value with no conversion, and is the one to reach for by default.
console.log(0 == ""); // true (coerced)
console.log(0 === ""); // false (no coercion)Functions and closures
A function defined inside another function keeps access to the outer function’s variables even after the outer function has finished running. This is called a closure, and it is the basis of patterns like counters and memoisation.
function makeCounter() {
let count = 0;
return () => ++count;
}
const counter = makeCounter();
counter(); counter(); // 2The event loop, briefly
JavaScript runs on a single thread. Synchronous code runs first, then microtasks (promise callbacks), then macrotasks (timers, I/O). This is why a `setTimeout(fn, 0)` still runs after the rest of the current script.
console.log("A");
setTimeout(() => console.log("B"), 0);
Promise.resolve().then(() => console.log("C"));
console.log("D");
// A, D, C, BCommon mistakes
- Using `var` inside a loop and expecting each iteration to capture its own value (it does not; `let` does).
- Relying on `==` where `===` was meant, letting type coercion change the result of a comparison.
- Assuming `array.forEach` can be awaited meaningfully inside an async callback; it does not wait for each iteration.
- Forgetting that `this` inside a regular function depends on how the function is called, not where it is defined (arrow functions behave differently).
Quick recap
- Prefer `const` by default, `let` when reassignment is needed, and avoid `var`.
- Use `===` and `!==` unless you specifically want type coercion.
- Closures let inner functions remember variables from an outer scope after it has returned.
- Synchronous code runs first, then microtasks, then macrotasks like `setTimeout`.
Ready to test this? Take the JavaScript Fundamentals quiz →
Roadmap
Work through the levels in order, or jump to where you are.
JavaScript quizzes
- JavaScriptBeginner
JavaScript Fundamentals
Types, coercion and equality
TypesEqualityVariables7 Qs~5mStart - JavaScriptIntermediate
Functions, Scope & Closures
Closures, hoisting, this and higher-order functions
ScopeClosuresthis7 Qs~5mStart - JavaScriptAdvanced
Async JavaScript
Event loop, promises and async/await
Event loopasync/awaitPromises7 Qs~5mStart
Interactive JavaScript challenges
Hands-on activities: find bugs, complete code, order steps and match concepts.
JavaScript articles
JavaScript Quiz Preparation: Common Traps and How to Practise
What JavaScript quizzes really test, the type coercion, scope and async traps that catch learners, and a step-by-step way to prepare for tests and interviews.
JavaScript Interview Questions and Answers
Common JavaScript interview questions on closures, hoisting, promises, the event loop and array methods, answered concisely so you can explain them confidently.
FAQ
Do the quizzes cover Node.js or the browser?
These quizzes cover the language itself (ECMAScript), which applies to both.
Do you cover TypeScript?
No, these quizzes are strictly vanilla JavaScript. We plan to release a dedicated TypeScript roadmap in the future.
How is asynchronous JavaScript covered?
We have dedicated quizzes covering the event loop, Promises, async/await, and error handling. You will be asked to predict the console output of mixed synchronous and asynchronous code.
Why is JavaScript equality so tricky?
Because of type coercion. Our fundamentals quizzes explicitly test the difference between == and ===, and edge cases like comparing null, undefined, and objects.