Skip to content
Kuza Ndoto Academy

JavaScript Quiz

Beginner → IntermediateChapter 7 · Page 32 of 325 min readUpdated 15 Nov 2026

Test what you have learned across the whole JavaScript series, from data types to promises and classes. Work out each answer before you open it, and follow the links to revise any topic you miss.

Basics

1. What does this print?

console.log(typeof null);
  • A) null
  • B) undefined
  • C) object
  • D) string
Show answer

C. typeof null is "object", a famous quirk kept since JavaScript's first version for compatibility (see Data Types).

2. What does this print?

console.log("5" == 5, "5" === 5);
Show answer

true false. == converts types before comparing; === also checks the type, so a string never equals a number. Prefer === (see Operators).

3. What does this print?

const items = 3;
const price = 50;
console.log(`Total: KES ${items * price}`);
Show answer

Total: KES 150. A template literal evaluates the expression inside ${ } and inserts the result (see Strings & Template Literals).

Functions, objects and arrays

4. What does this print?

const result = [1, 2, 3, 4]
  .filter((n) => n % 2 === 0)
  .map((n) => n * 10);
console.log(result);
Show answer

[20, 40]. filter keeps the even numbers 2 and 4, then map multiplies each by 10 (see Array Methods).

5. What does this print?

function makeCounter() {
  let count = 0;
  return () => ++count;
}
const next = makeCounter();
next();
console.log(next(), next());
Show answer

2 3. The inner function is a closure that remembers count between calls. The first call makes it 1, then the two calls in console.log return 2 and 3 (see Scope & Closures).

6. What is rest?

const { name, ...rest } = { name: "Amina", age: 19, town: "Kisumu" };
console.log(rest);
Show answer

{age: 19, town: 'Kisumu'}. Destructuring pulls out name, and the rest syntax collects the remaining properties into a new object (see Objects).

The DOM and events

7. The page contains <ul id="list"><li>Mango</li></ul>. What is logged when you click "Mango"?

document.querySelector("#list").addEventListener("click", (event) => {
  console.log(event.target.tagName, event.currentTarget.id);
});
Show answer

LI list. The click starts on the li (the target) and bubbles up to the ul, where the listener runs (the current target). This is the basis of event delegation (see Events).

8. In a form's submit handler, what does event.preventDefault() do?

  • A) Clears all the form fields
  • B) Stops the browser's default submission, so the page doesn't reload
  • C) Stops the event from bubbling to parent elements
  • D) Validates the inputs
Show answer

B. It cancels the browser's built-in action (sending the form and loading a new page), so your JavaScript can handle the data. Stopping bubbling is stopPropagation() (see Handling Forms).

Asynchronous JavaScript

9. In what order are the letters logged?

console.log("A");
setTimeout(() => console.log("B"), 0);
Promise.resolve().then(() => console.log("C"));
console.log("D");
Show answer

A, D, C, B. Synchronous code runs first (A, D). Then the event loop runs microtasks such as promise callbacks (C) before tasks such as timers (B), even with a 0 ms delay (see Callbacks & the Event Loop).

10. What does this print?

async function getAge() {
  return 19;
}
console.log(getAge() instanceof Promise);
Show answer

true. An async function always returns a promise; here it is fulfilled with 19. To get the number, use await getAge() or .then() (see Async & Await).

11. You fetch a URL and the server replies with status 404. What happens to the promise?

  • A) It rejects with an error
  • B) It fulfils with a Response whose ok is false
  • C) It fulfils with null
  • D) It never settles
Show answer

B. fetch only rejects when the request fails completely (for example, no network). Any HTTP reply fulfils the promise, so you must check response.ok yourself (see Fetch & APIs).

12. What does this print?

localStorage.setItem("cart", ["unga", "sukari"]);
console.log(localStorage.getItem("cart"));
Show answer

unga,sukari. localStorage only stores strings, so the array was converted with its toString() method, and you get back text, not an array. Save with JSON.stringify and load with JSON.parse instead (see Local Storage and JSON).

Modern JavaScript

13. What does this print?

try {
  throw new Error("Oops");
} catch (error) {
  console.log("catch:", error.message);
} finally {
  console.log("finally");
}
console.log("after");
Show answer

catch: Oops, then finally, then after. The error jumps to catch, finally always runs, and because the error was handled the program continues (see Error Handling).

14. format.js contains export default function formatKES(n) {...}. Which import works in the browser?

  • A) import { formatKES } from "./format.js";
  • B) import formatKES from "./format.js";
  • C) import formatKES from "format";
  • D) import * from "./format.js";
Show answer

B. A default export is imported without braces, and browser imports need a relative path with the .js extension. A would only work for a named export, and D is invalid syntax (see Modules).

15. What does this print?

class Animal {
  constructor(name) {
    this.name = name;
  }
  speak() {
    return `${this.name} makes a sound`;
  }
}

class Dog extends Animal {
  speak() {
    return `${super.speak()}: woof!`;
  }
}

console.log(new Dog("Simba").speak());
Show answer

Simba makes a sound: woof!. Dog has no constructor, so the parent's constructor runs with the same arguments. Dog overrides speak and calls the parent's version with super.speak() (see Classes).

How did you do?

  • 13–15: Excellent. You are ready to build real projects; try extending the to-do app.
  • 9–12: Solid. Revisit the pages linked from the questions you missed.
  • 0–8: Keep going. Work through the series again, running every example in the Try-it editor.
You've reached the end of the seriesGet certified in JavaScriptContinue in Kuza Ndoto Academy with projects, mentor feedback and a certificate.
→

Tip: use the ← and → keys to move between pages.