Technology Technology · Programming ● Medium

JavaScript Fundamentals quiz

This 10-question JavaScript fundamentals quiz covers block scope, strict equality, closures, JSON parsing, const bindings, array methods, promises, null and undefined, and spread syntax. The explanations include important edge cases where a short answer needs qualification, making the page useful both as a beginner knowledge check and as a focused refresher linked to the language specification and MDN documentation.

Start the quiz
Questions
10
Time
14 min
Difficulty
● Medium
A developer exploring a visual system of variables, transformations, nested scope, arrays, and asynchronous flow
Technology · Medium
TestYourChoice original artwork
Quick info

Before you start

Best for

Beginners validating their grasp of core JavaScript

Format

10 explanation-backed questions in about 14 minutes.

What you'll cover

A small map of the test

  1. 1Variables, scope, and the let/const/var distinction
  2. 2Closures, the spread operator, and array methods like map()
  3. 3Strict versus loose equality and the null/undefined difference
  4. 4Promises and asynchronous JavaScript
Audience

Who this quiz is for

  • Beginners validating their grasp of core JavaScript
  • Experienced developers brushing up on the fundamentals
Key concepts

Ideas this quiz checks

Closure

A function that retains access to variables from its lexical scope even after the outer function has returned.

Strict equality (===)

A comparison that checks both value and type without coercion, avoiding surprising type conversions.

Promise

An object representing the eventual result of an asynchronous operation, which may resolve or reject.

Spread operator (...)

Syntax that expands an iterable into its individual elements to copy or merge arrays and objects.

Score guide

How to read your score

  1. 80–100% Strong command

    You understand most of the core ideas and can use the explanations to polish smaller gaps.

  2. 50–79% Solid base

    You know part of the topic, but the missed explanations are the highest-value review material.

  3. 0–49% Review first

    Treat this as a starting map: revisit the key concepts, then retake the quiz for a cleaner signal.

After the quiz

Recommended next steps

  • Read JavaScript Concepts Every Developer Should Know for a deeper walkthrough of closures, the event loop, and promises
  • Take the Web Development Fundamentals Quiz to broaden beyond the language itself
  • Try the Git Commands Quiz to round out your everyday developer toolkit
References

Sources and further reading

How to play

Instructions

  1. You have 14 minutes total to answer 10 multiple-choice questions.
  2. Choose an answer to lock it in. The runner immediately shows the correct answer and explanation.
  3. Use Hint when you want a nudge, or Skip to move forward without answering.
  4. Keyboard shortcuts: A-D answer, H hints, S skips, Enter/ next, and previous.
  5. No signup required. Your progress is local to this quiz session.
Every question, explained

Answer key and explanations

All 10 questions from this quiz, with the correct answer and the reasoning behind it. Take the quiz first if you want an honest score — or read straight through and use this as revision material.

  1. Which keyword declares a block-scoped variable in modern JavaScript?

    • var
    • letCorrect
    • def
    • dim

    Why: `let` declares a binding scoped to its enclosing block. A `var` declaration is scoped to a function body or, outside a function, to its surrounding script or module context rather than an ordinary block. Both forms have declaration-instantiation behavior before execution, but accessing a `let` binding before its declaration is evaluated triggers the temporal dead zone rather than returning `undefined`.

  2. Which statement best describes JavaScript's strict equality operator (`===`)?

    • It converts both operands to strings before comparing them
    • It compares without implicit type conversion, so operands of different types are normally unequalCorrect
    • It checks only whether the operands have the same type
    • It performs a deep comparison of object properties

    Why: Strict equality compares operands without converting one type into another, so `5 === "5"` is false. Values of the same primitive type follow that type's equality rules; two distinct objects are unequal even if their properties look identical because objects compare by identity. It is therefore more precise than saying the operator always checks a generic 'value and type equality.'

  3. What is a closure in JavaScript?

    • A way to close the browser window
    • A function that retains access to its outer scope after the outer function has returnedCorrect
    • A method to terminate a loop
    • A syntax for defining classes

    Why: A closure is a function that remembers and can access variables from its lexical scope even when the function is executed outside that scope. Closures are fundamental to patterns like module encapsulation, callbacks, and factory functions in JavaScript.

  4. Which method converts a JSON string into a JavaScript object?

    • JSON.stringify()
    • JSON.parse()Correct
    • JSON.decode()
    • JSON.convert()

    Why: JSON.parse() takes a JSON-formatted string and converts it into a JavaScript object or value. Its counterpart, JSON.stringify(), does the reverse — converting a JavaScript object into a JSON string. These two methods together enable round-trip serialization.

  5. What is the output of 'typeof null' in JavaScript?

    • 'null'
    • 'undefined'
    • 'object'Correct
    • 'boolean'

    Why: typeof null returns 'object', which is a well-known quirk and historical bug in JavaScript. It has been kept for backwards compatibility since fixing it would break existing code. To properly check for null, use strict equality: value === null.

  6. What happens if you try to reassign a variable declared with 'const'?

    • The reassignment succeeds silently
    • It throws a TypeError, because 'const' bindings cannot be reassignedCorrect
    • The variable is automatically converted to 'let'
    • Nothing happens and the value stays the same

    Why: A variable declared with 'const' cannot be reassigned to a new value — attempting it throws a TypeError. Note that 'const' makes the binding constant, not the value: if a const holds an object or array you can still mutate its contents (for example, push to the array); you simply cannot point the variable at something else.

  7. Which array method returns a new array containing the results of calling a function on every element?

    • forEach()
    • map()Correct
    • filter()
    • reduce()

    Why: `Array.prototype.map()` creates a new array by applying a callback to each element and collecting the return values. The `map()` operation itself does not replace elements in the source array, although callback code can still mutate the source or objects referenced by it. `forEach()` returns `undefined`, `filter()` selects elements, and `reduce()` accumulates a result.

  8. What does a JavaScript Promise represent?

    • A guarantee that code will never throw an error
    • The eventual result of an asynchronous operation, which may resolve or rejectCorrect
    • A way to pause the entire program until data loads
    • A special type of loop for repeated tasks

    Why: A Promise represents the eventual completion or failure of an asynchronous operation. It starts pending and later becomes fulfilled or rejected. 'Resolved' is broader than 'fulfilled': a promise can be resolved to follow another still-pending promise. Handlers can be registered with `.then()` and `.catch()`, while `async`/`await` provides syntax built on promises.

  9. What is the difference between 'undefined' and 'null' in JavaScript?

    • They are identical and fully interchangeable
    • 'undefined' means a variable was declared but not assigned a value; 'null' is an intentional 'no value' assigned by the programmerCorrect
    • 'null' is a syntax error while 'undefined' is valid
    • 'undefined' is only for numbers and 'null' only for strings

    Why: 'undefined' usually means a variable has been declared but not yet given a value (or a function returned nothing). 'null' is a value that represents the intentional absence of any object value — a programmer deliberately setting 'nothing.' For comparison, 'undefined == null' is true with loose equality, but 'undefined === null' is false because their types differ.

  10. In the expression 'const combined = [...a, ...b]', what does the spread operator (...) do?

    • It subtracts array b from array a
    • It expands the elements of arrays a and b into a new combined arrayCorrect
    • It creates a reference so that changes to a also change combined
    • It sorts the elements of both arrays

    Why: In an array literal, spread syntax expands iterable values into a new array, so `[...a, ...b]` contains the elements of `a` followed by those of `b`. The copy is shallow: nested objects remain shared references. Object spread is related syntax that copies own enumerable properties into a new object; an ordinary object does not have to be iterable for object spread to work.