All JavaScript quizzes
Beginner30 questions30 minutes

JavaScript Beginner Quiz

Variables, types, functions and arrays — the basics, checked by reading code rather than reciting definitions.

Start the quiz

Sample questions from this quiz

A preview of the style and depth. Try each one, then reveal the answer — or skip straight to the timed quiz.

1. What does this print?

let x = 5
x = x + '5'
console.log(x, typeof x)
  • 55 number
  • 10 number
  • 55 string
  • NaN number
Show answer

Answer: 55 string. When `+` has a string on either side it concatenates rather than adds, converting the number to text. Every other arithmetic operator does the opposite and converts the string to a number — `5 - '5'` is 0.

2. What does this print?

const arr = [1, 2, 3]
arr.push(4)
console.log(arr.length, arr[0], arr[10])
  • 4 1 undefined
  • 4 1 null
  • 3 1 undefined
  • 4 0 undefined
Show answer

Answer: 4 1 undefined. `push` adds to the end, so length becomes 4. Arrays are zero-indexed, so `arr[0]` is 1. Reading past the end gives `undefined` rather than throwing — which is why an out-of-range read often shows up much later as a confusing error.

3. This should add two numbers but returns '12'. Which line is wrong?

1  function add(a, b) {
2    return a + b
3  }
4  const total = add(prompt('x'), prompt('y'))
  • Line 2 — the return needs parentheses
  • Line 4 — prompt returns strings, so + concatenates
  • Line 1 — parameters need type annotations
  • Line 3 — the function is missing a semicolon
Show answer

Answer: Line 4 — prompt returns strings, so + concatenates. `prompt` always yields a string, so `'1' + '2'` gives '12'. Convert first with `Number(...)` or `parseInt(..., 10)`. The same trap applies to values read from form inputs and URL parameters.

Frequently asked questions

How many questions are in this JavaScript quiz?+

30 questions, with a 30-minute time limit. Every question includes a written explanation of the correct answer.

Is this JavaScript quiz free?+

Yes. Every quiz on CodexQuizz is free and needs no account. You only enter a name if you choose to post your score to the leaderboard.

What level is the beginner quiz aimed at?+

Variables, types, functions and arrays — the basics, checked by reading code rather than reciting definitions.

Can I use this to prepare for a JavaScript interview?+

Yes. The questions cover the topics that come up in JavaScript technical screens, and the explanations are written so that a wrong answer still teaches you the underlying concept.

Ready to test your JavaScript?

30 questions, 30 minutes. Free, no sign-up.

Start now