JavaScript220 questions in the bank

JavaScript Quiz: Test Your JavaScript Knowledge

Pick how many questions you want, choose a difficulty and go. You'll see why each answer is right or wrong, then you can retry to beat your score.

Questions
Difficulty
Topic
Mode
  1. Where does console.log() show its output?

    • On the web page
    • In a pop-up window
    • In the browser's developer console
    • In the address bar
  2. JavaScript and Java are the same language.

    • True
    • False
  3. In what order do statements run?

    • Bottom to top
    • Shortest first
    • Randomly
    • Top to bottom, one after another
  4. What does console.log(3 + 4) print?

    • 34
    • 7
    • 3 + 4
    • Nothing
  5. What file extension do JavaScript files use?

    • .js
    • .java
    • .jsx only
    • .script
  6. What's the difference between async and defer?

    • There is none
    • defer runs in order after parsing; async runs as soon as it downloads, in any order
    • async is faster in all cases
    • defer only works on inline scripts
  7. Can a <script src="x.js"> also contain code between its tags?

    • No, the inline code is ignored
    • Yes, both run
    • Only comments
    • Only if type="module"
  8. Which method prints a red error message?

    • console.error
    • console.log
    • console.red
    • console.fail
  9. What does console.log("a", "b") print?

    • ab
    • "a", "b"
    • a b
    • a,b
  10. Why should you avoid document.write()?

    • It's too slow
    • It can overwrite the whole page after it has loaded
    • It only works in Firefox
    • It prints to the console
  11. Which keyword should you use by default?

    • var
    • const
    • let
    • variable
  12. What is the value of a variable declared with let x; and nothing else?

    • 0
    • null
    • ""
    • undefined
  13. Are score and Score the same variable?

    • Yes
    • No, because JavaScript is case-sensitive
    • Only if declared with var
    • Only inside functions
  14. Which of these is a boolean?

    • "true"
    • 0
    • "no"
    • false
  15. What's the difference between undefined and null?

    • undefined means no value was assigned; null is deliberately empty
    • They're identical
    • null is a number
    • undefined is a string
  16. How do you reliably check if a value is an array?

    • typeof x === "array"
    • Array.isArray(x)
    • x.type === "array"
    • x instanceof List
  17. What does x++ do?

    • Doubles x
    • Adds 1 to x
    • Adds x to itself
    • Nothing
  18. What is true && false?

    • false
    • true
    • undefined
    • An error
  19. What does const msg = 7 > 5 ? "yes" : "no"; store?

    • "no"
    • true
    • "yes"
    • 7
  20. What is "2" * "3"?

    • "23"
    • "6"
    • NaN
    • 6
  21. What is "hello".length?

    • 4
    • 6
    • 5
    • "hello"
  22. Which quote type allows ${variables} and multiple lines?

    • "double"
    • 'single'
    • backticks
    • All of them
  23. What does "\n" represent?

    • The letter n
    • A new line
    • A null value
    • A tab
  24. What does "Hi".repeat(3) return?

    • "HiHiHi"
    • "Hi3"
    • ["Hi", "Hi", "Hi"]
    • "Hi Hi Hi"
  25. What does "banana".indexOf("z") return?

    • 0
    • null
    • -1
    • false
  26. What is "one two three".split(" ")?

    • ["one", "two", "three"]
    • "onetwothree"
    • ["o", "n", "e", …]
    • 3
  27. What does Math.random() return?

    • A whole number from 1 to 100
    • A decimal from 0 up to (but not including) 1
    • Always 0.5
    • A random string
  28. What does parseInt("25px") return?

    • NaN
    • 25
    • "25"
    • 25px
  29. What type does (5).toFixed(2) return?

    • number
    • boolean
    • string
    • NaN
  30. What does 0.1 + 0.2 === 0.3 evaluate to?

    • false
    • true
    • NaN
    • An error
  31. What does 10 >= 10 return?

    • false
    • true
    • 10
    • undefined
  32. What does "3" === 3 return?

    • true
    • NaN
    • false
    • An error
  33. How many falsy values are there in JavaScript?

    • 6 (false, 0, "", null, undefined, NaN)
    • 2
    • 4
    • Every value is falsy
  34. What does !true return?

    • true
    • null
    • An error
    • false
  35. What does null || "x" return?

    • "x"
    • null
    • true
    • false
  36. When should you use ?? instead of ||?

    • Always
    • Never
    • Only with strings
    • When 0, "" or false are valid values that shouldn't be replaced
  37. What does x > 10 ? "big" : "small" return when x is 4?

    • "big"
    • true
    • "small"
    • 4
  38. What does false && expensiveCheck() do?

    • Runs expensiveCheck and returns false
    • Returns false without calling expensiveCheck
    • Throws an error
    • Returns undefined
  39. When does the else block run?

    • Always
    • When the first condition is true
    • Never
    • When all previous conditions are false
  40. How many blocks can run in one if/else if/else chain?

    • All whose conditions are true
    • Exactly two
    • At most one
    • Unlimited
  41. What does if ("0") { … } do?

    • Skips the block
    • Throws an error
    • Runs the block, because "0" is a non-empty string (truthy)
    • Converts "0" to false
  42. What does default do in a switch?

    • Runs when no case matches
    • Runs first
    • Sets a default value
    • Is required
  43. Which comparison does switch use?

    • ==
    • >
    • It depends on the type
    • ===
  44. How do you make two cases run the same code?

    • case "a" || "b":
    • case ["a", "b"]:
    • Write case "a": and case "b": one after the other, then the code
    • It's not possible
  45. Which loop is simplest for going through every item of an array?

    • for…in
    • while
    • switch
    • for…of
  46. What does continue do inside a loop?

    • Stops the loop
    • Restarts the loop from the beginning
    • Skips to the next iteration
    • Pauses for a second
  47. For an array of length 5, what is the last valid index?

    • 4
    • 5
    • 6
    • -1
  48. When does a while loop stop?

    • When its condition becomes false (or on break)
    • After 10 laps
    • When the page reloads
    • Never
  49. When should you prefer while over for?

    • When looping over an array
    • Always
    • When you don't know in advance how many laps you need
    • Never, because while is outdated
  50. What does while (true) { … } need to avoid running forever?

    • continue
    • A semicolon
    • Nothing, because it stops automatically
    • A break inside it
  51. Which loop is best for the values of an array?

    • for...in
    • for...of
    • do...while
    • switch
  52. What does continue do?

    • Skips to the next iteration
    • Ends the program
    • Restarts the loop from the beginning
    • Exits all loops
  53. How do you get index and value in a for...of loop?

    • for (const i, v of arr)
    • for (const v in arr)
    • arr.indexOf inside the loop
    • for (const [i, v] of arr.entries())
  54. Which of these is NOT iterable with for...of?

    • A plain object
    • A string
    • A Set
    • A NodeList
  55. In nested loops, what does a plain break affect?

    • All loops
    • The outer loop
    • Only the innermost loop
    • Nothing
  56. How do you call a function named start?

    • call start
    • start
    • start()
    • function start()
  57. What's the difference between a parameter and an argument?

    • There is no difference
    • Arguments are in the definition
    • Parameters are always numbers
    • Parameters are placeholders in the definition; arguments are the actual values passed in
  58. What does a function return if it has no return statement?

    • undefined
    • null
    • 0
    • An error
  59. What happens to code written after return in the same block?

    • It runs after the return
    • It never runs
    • It runs before the return
    • It causes a syntax error
  60. Which is a valid arrow function?

    • const f = => 1;
    • const f = () -> 1;
    • const f = () => 1;
    • const f = function => 1;
  61. When does an arrow function return a value automatically?

    • When the body is a single expression without curly braces
    • Always
    • When it has one parameter
    • Never
  62. Why shouldn't you use an arrow function as an object method that uses this?

    • Arrows don't have their own this; they use the surrounding one
    • Arrows are slower
    • Arrows can't be stored in objects
    • It's a syntax error
  63. Which keyword ignores block scope and should be avoided?

    • let
    • const
    • var
    • function
  64. What is a closure?

    • A function that closes the browser
    • A function that remembers variables from the scope where it was created
    • A finished loop
    • A way to end a program
  65. What happens if you use a let variable before its declaration line?

    • ReferenceError (temporal dead zone)
    • It's undefined
    • It's 0
    • It works normally
  66. Which should you use by default for new variables?

    • const
    • var
    • let
    • global
  67. Which can be called before the line it's defined on?

    • const save = () => {}
    • const save = function () {}
    • function save() {}
    • class Save {}
  68. What does "use strict" do to an assignment to an undeclared variable?

    • Creates a global
    • Ignores it
    • Converts it to let
    • Throws a ReferenceError
  69. Are JavaScript modules in strict mode?

    • Yes, automatically
    • Only with "use strict"
    • No, never
    • Only in Node.js
  70. Why does for (var i...) with setTimeout log the same number three times?

    • setTimeout is broken
    • There's one shared i, and the callbacks run after the loop has finished
    • var is slower
    • The loop runs three times too fast
  71. Which is a higher-order function?

    • Math.PI
    • array.map
    • console
    • "text".length
  72. What's wrong with setTimeout(alertUser(), 1000)?

    • Nothing
    • The delay is too short
    • setTimeout needs a string
    • alertUser runs immediately and its result is passed instead
  73. What is callback hell?

    • An error message
    • Deeply nested callbacks that are hard to read and maintain
    • A callback that never runs
    • A browser setting
  74. Does the callback passed to array.map run synchronously?

    • Yes, once per item, before map returns
    • No, it runs later
    • Only for the first item
    • Only in Node.js
  75. Why does each call to makeCounter() keep its own count?

    • Counters are global
    • JavaScript copies the function
    • Because of let
    • Each call creates a new scope, and the returned functions close over that scope
  76. What is recursion?

    • A loop inside a loop
    • A function with many arguments
    • Repeating code by copying it
    • A function calling itself
  77. Which data is recursion best suited for?

    • A flat list of prices
    • A single number
    • A tree, such as folders inside folders
    • A short string
  78. What happens to each call while it waits for the next one?

    • It's deleted
    • It stays on the call stack until it can finish
    • It runs in parallel
    • It moves to the heap
  79. Can every recursive function be written as a loop?

    • Yes, possibly with your own stack array
    • No, never
    • Only factorial
    • Only in Python
  80. In return n * fact(n - 1), when is the multiplication done?

    • Before fact(n - 1) is called
    • At the same time
    • After fact(n - 1) returns its result
    • Never
  81. What is the index of the first item in an array?

    • 0
    • 1
    • -1
    • It depends
  82. Which method removes the last item and returns it?

    • shift()
    • slice()
    • remove()
    • pop()
  83. What does ["a", "b"].indexOf("z") return?

    • 0
    • null
    • -1
    • false
  84. Which method copies part of an array without changing the original?

    • splice
    • pop
    • shift
    • slice
  85. Does map change the original array?

    • Yes
    • No, it returns a new array
    • Only for numbers
    • Only if you use const
  86. What does [1, 2, 3].filter(n => n > 5) return?

    • []
    • undefined
    • null
    • false
  87. What's the difference between sort() and toSorted()?

    • toSorted is alphabetical only
    • There's no difference
    • sort is newer
    • sort changes the original array; toSorted returns a sorted copy
  88. In reduce((acc, n) => acc + n, 0), what is acc?

    • The current index
    • The original array
    • The running result (accumulator) from the previous step
    • Always 0
  89. What does [2, 10, 1].sort() return?

    • [1, 2, 10]
    • [10, 2, 1]
    • An error
    • [1, 10, 2]
  90. What should a compare function return when a should come first?

    • A positive number
    • true
    • Zero
    • A negative number
  91. What does every() return for an empty array?

    • false
    • true
    • undefined
    • An error
  92. What's the difference between sort and toSorted?

    • toSorted is slower
    • toSorted only works on numbers
    • sort changes the original array; toSorted returns a new sorted array
    • There's none
  93. In (a, b) => a.team.localeCompare(b.team) || b.score - a.score, when is the score used?

    • Only when the teams are equal, because localeCompare returns 0
    • Always
    • Never
    • Only for the first item
  94. What is a property?

    • A function
    • A key and value pair in an object
    • An array index
    • A CSS rule
  95. What does Object.keys({ a: 1, b: 2 }) return?

    • [1, 2]
    • 2
    • { a, b }
    • ["a", "b"]
  96. When must you use bracket notation?

    • When the key is stored in a variable or contains spaces/dashes
    • Always
    • For numbers only
    • Never
  97. What does Object.values({ a: 1, b: 2 }) return?

    • ["a", "b"]
    • [1, 2]
    • [["a", 1], ["b", 2]]
    • 2
  98. In { ...a, ...b }, which value wins if both have the same key?

    • a's
    • b's, because it comes later
    • Neither, it's an error
    • The larger one
  99. Is Object.freeze deep?

    • No, nested objects can still change
    • Yes, every level
    • Only for arrays
    • Only in strict mode
  100. What does JSON.parse(JSON.stringify(obj)) lose?

    • Strings
    • Numbers
    • Nothing
    • Functions, undefined values, and Date objects (which become strings)
  101. What's the difference between Object.hasOwn(obj, "x") and "x" in obj?

    • None
    • hasOwn checks only the object itself; in also checks its prototype chain
    • in only works on arrays
    • hasOwn checks values
  102. When is the value of this decided for a normal function?

    • When the function is written
    • When the page loads
    • It never changes
    • When the function is called
  103. Do arrow functions have their own this?

    • No, they use this from the surrounding code
    • Yes, always the window
    • Yes, the arrow itself
    • Only in classes
  104. Which method takes arguments as an array?

    • call
    • apply
    • bind
    • map
  105. In a normal function event listener, what is this?

    • The event object
    • The window, always
    • The element the listener is attached to
    • undefined
  106. What is this inside a plain function call in strict mode?

    • window
    • The function itself
    • null
    • undefined
  107. What does const [x, y] = [7, 8]; do?

    • Sets x to 7 and y to 8
    • Creates an array
    • Sets x and y to [7, 8]
    • Throws an error
  108. What does { ...a, ...b } do when both have a key id?

    • Throws an error
    • Keeps b's id (the later one wins)
    • Keeps a's id
    • Creates an array of both ids
  109. In function f(...args), what is args?

    • The first argument
    • A string
    • An object
    • An array of all the arguments
  110. What happens when you add a value that's already in a Set?

    • An error
    • It's stored twice
    • The old one is removed
    • Nothing, it's ignored
  111. How do you get the number of entries in a Map?

    • map.length
    • map.count()
    • map.size
    • Object.keys(map).length
  112. What order does a Map keep its entries in?

    • Alphabetical
    • Random
    • By value
    • The order they were added
  113. How do you turn a Map into a plain object?

    • JSON.parse(map)
    • Object.fromEntries(map)
    • map.toObject()
    • { ...map }
  114. Why is WeakMap useful for data attached to DOM elements?

    • Entries disappear automatically when the element is no longer used, avoiding memory leaks
    • It's faster to loop over
    • It accepts string keys
    • It can be saved as JSON
  115. What does new Date() give you?

    • 1 January 1970
    • An empty date
    • The current date and time
    • An error
  116. What is a JavaScript date stored as internally?

    • A string
    • Seconds since the year 0
    • An array of numbers
    • Milliseconds since 1 January 1970 UTC
  117. Which date string format is safest to parse?

    • "03/14/2026"
    • "2026-03-14"
    • "14 March 26"
    • "March the 14th"
  118. How do you add 7 days to date d?

    • d + 7
    • d.addDays(7)
    • d.setDate(d.getDate() + 7)
    • d.getDate() + 7
  119. Why store dates as UTC ISO strings?

    • They mean the same moment everywhere, whatever the time zone
    • They're shorter
    • Browsers can't read local times
    • JSON doesn't support numbers
  120. What does \d match?

    • A letter
    • A digit
    • A space
    • A dollar sign
  121. What does the g flag do?

    • Makes the match greedy
    • Groups the pattern
    • Ignores case
    • Finds all matches instead of only the first
  122. In "2026-03".replace(/(\d+)-(\d+)/, "$2/$1"), what is the result?

    • "03/2026"
    • "2026/03"
    • "$2/$1"
    • "03-2026"
  123. Which quantifier makes something optional?

    • +
    • ?
    • *
    • {2}
  124. Why does /\bcat\b/ not match "concatenate"?

    • It's case-sensitive
    • concatenate is too long
    • \b requires a word boundary on each side, so cat must be a whole word
    • \b means "begins with b"
  125. What does DOM stand for?

    • Document Object Model
    • Data Object Manager
    • Digital Output Mode
    • Document Order Map
  126. Which method do NodeLists not have?

    • forEach
    • map
    • length
    • item
  127. How do you search only inside a specific element panel?

    • document.querySelector(panel, "p")
    • panel.find("p")
    • panel.querySelector("p")
    • document.panel("p")
  128. Which method creates a new element?

    • document.newElement("p")
    • document.make("p")
    • new Element("p")
    • document.createElement("p")
  129. How do you read data-price="12" from an element?

    • el.price
    • el.data("price")
    • el.attributes.price
    • el.dataset.price
  130. In JavaScript, what is the CSS property font-size called on el.style?

    • fontSize
    • font-size
    • FontSize
    • font_size
  131. Which method adds content at the start of a parent?

    • prepend
    • append
    • before
    • after
  132. What does el.closest(".card") return?

    • The next .card on the page
    • The nearest ancestor (or el itself) matching .card
    • All .card children
    • The first .card in the document
  133. What happens if you append an element that's already on the page?

    • It's copied
    • An error
    • Nothing
    • It moves to the new place
  134. What is a template element for?

    • Styling forms
    • Loading scripts
    • Defining CSS variables
    • Holding inert markup you can clone and fill with JavaScript
  135. Why insert many elements with one append(...items) call?

    • append only accepts arrays
    • One insertion means one layout update instead of many
    • It removes duplicates
    • It makes elements focusable
  136. Which method attaches an event handler?

    • el.onEvent()
    • el.listen()
    • el.handle()
    • el.addEventListener()
  137. What is event.target?

    • The function that handles the event
    • The element the event actually happened on
    • The parent element
    • The window
  138. What is event delegation?

    • Adding the same listener to every child
    • Passing events to a server
    • Putting one listener on a parent and handling events from its children
    • Removing listeners automatically
  139. Which method stops a link from navigating?

    • stopPropagation()
    • preventDefault()
    • return false in addEventListener
    • removeEventListener()
  140. Which of these events does NOT bubble?

    • focus
    • click
    • input
    • keydown
  141. What does { once: true } do?

    • Runs the listener in the capture phase
    • Prevents the default action
    • Stops bubbling
    • Removes the listener automatically after it runs once
  142. How do you check whether a click happened outside a menu?

    • !menu.contains(event.target)
    • event.target === document
    • event.outside
    • menu.isClicked === false
  143. Which phase runs listeners added with { capture: true }?

    • Bubbling
    • Only the target phase
    • Capturing, on the way down before the target
    • After all bubbling listeners
  144. Which event should you listen for to handle a form being sent?

    • submit
    • click
    • change
    • send
  145. Why must form fields have a name to appear in FormData?

    • For styling
    • FormData uses the name attribute as each value's key
    • Names make fields required
    • It's only needed for checkboxes
  146. How do you connect an error message to a field for screen readers?

    • Put it in the placeholder
    • Give the field aria-describedby with the message element's id
    • Use alert()
    • Colour the border red
  147. Which event fires on every keystroke in a text field?

    • input
    • change
    • submit
    • blur
  148. Why validate again on the server?

    • Browsers can't validate
    • It's faster
    • Client-side checks can be bypassed, so the server must not trust incoming data
    • Only servers can check emails
  149. What unit is the delay in setTimeout?

    • Seconds
    • Minutes
    • Frames
    • Milliseconds
  150. Does setTimeout pause the rest of your code?

    • No. It schedules the function and the code continues immediately
    • Yes
    • Only for long delays
    • Only in loops
  151. What is debouncing?

    • Running code faster
    • Waiting until events stop for a moment before running code
    • Repeating code forever
    • Removing bugs automatically
  152. What does debounce do?

    • Runs code faster
    • Runs code at a fixed rate forever
    • Removes event listeners
    • Waits until events stop for a while, then runs once
  153. With a 1000ms throttle and constant events for 5 seconds, roughly how many times does the function run?

    • Once
    • Hundreds of times
    • About 5 times
    • Never
  154. Why do debounce and throttle need closures?

    • The returned function must remember the timer or last run time between calls
    • To make them asynchronous
    • Closures run faster
    • To access the DOM
  155. What does a leading debounce do?

    • Runs only after the pause
    • Runs on the first event, then ignores the rest until things calm down
    • Runs twice
    • Runs before the page loads
  156. Why can a debounced search still show wrong results?

    • Debounce changes the search term
    • Debounce is unreliable
    • Servers ignore debounced requests
    • An older, slower request can finish after a newer one, so results must be checked as the latest
  157. Does localStorage data survive a page refresh?

    • No
    • Only for 1 hour
    • Yes
    • Only in Chrome
  158. What's the difference between localStorage and sessionStorage?

    • sessionStorage is cleared when the tab closes
    • sessionStorage is bigger
    • localStorage is server-side
    • No difference
  159. Should you store passwords in localStorage?

    • No. It's readable by any script on the page and in DevTools
    • Yes, it's encrypted
    • Only short ones
    • Only in sessionStorage
  160. What does JSON stand for?

    • Java Standard Object Notation
    • JavaScript Object Notation
    • JavaScript Online Network
    • JSON Simple Object Name
  161. What type does JSON.stringify([1, 2]) return?

    • array
    • object
    • string
    • number
  162. Can JSON contain functions?

    • Yes
    • No
    • Only arrow functions
    • Only in arrays
  163. What is location.pathname for https://site.com/blog/post?id=3?

    • https://site.com
    • /blog/post
    • ?id=3
    • post
  164. Which event fires when the user presses the back button after pushState?

    • load
    • hashchange only
    • unload
    • popstate
  165. What is the global object in the browser?

    • document
    • navigator
    • window
    • global
  166. Which API copies text to the clipboard?

    • document.copy()
    • navigator.clipboard.writeText(text)
    • window.clipboard = text
    • location.copy(text)
  167. What does threshold: 0.5 mean for an IntersectionObserver?

    • Check every half second
    • Watch half of the elements
    • Use half the screen as the root
    • Report when at least half of the element is visible
  168. What does matchMedia("(max-width: 600px)").matches return?

    • The screen width
    • A CSS rule
    • An event
    • true or false
  169. How do you best detect a touch-first device?

    • Check if the width is under 768px
    • Look for "Mobile" in the user agent
    • matchMedia("(pointer: coarse)")
    • Check for a keyboard
  170. Why should JavaScript use the same breakpoints as CSS?

    • So the behaviour and the layout always switch together
    • It's faster
    • Browsers require it
    • To use less memory
  171. When does a MediaQueryList's change event fire?

    • Every time the window resizes
    • Once on page load
    • When the query's result changes from true to false or back
    • Only on phones
  172. What does entry.contentRect.width give in a ResizeObserver callback?

    • The window width
    • The width including margins
    • The screen width
    • The element's content box width in pixels
  173. Which element do you draw on with the Canvas API?

    • svg
    • img
    • canvas
    • div
  174. How do you draw a full circle with arc?

    • arc(x, y, r, 0, 360)
    • circle(x, y, r)
    • arc(x, y, r, 0, Math.PI)
    • arc(x, y, r, 0, Math.PI * 2)
  175. How do you stop a requestAnimationFrame loop?

    • clearInterval(id)
    • cancelAnimationFrame(id)
    • stopAnimation()
    • return false
  176. Why does a canvas look blurry on a phone?

    • Phones don't support canvas
    • The colours are wrong
    • Its drawing size is smaller than the screen's real pixels, so it's stretched
    • requestAnimationFrame is too slow
  177. Why does each animation frame usually start with clearRect?

    • Canvas keeps old pixels, so shapes would leave trails without clearing
    • To release memory
    • It resets fillStyle
    • It's required by requestAnimationFrame
  178. When does the finally block run?

    • Always
    • Only if there was an error
    • Only if there was no error
    • Never
  179. Which error do you get from null.length?

    • ReferenceError
    • SyntaxError
    • RangeError
    • TypeError
  180. Can try…catch catch a SyntaxError in the same script?

    • Yes, always
    • No. Syntax errors stop the script before it runs
    • Only in functions
    • Only with finally
  181. What is the first thing to do with an error message?

    • Delete the line
    • Read its type, message and line number
    • Restart the browser
    • Add more code
  182. Why log variables as console.log({ price })?

    • The output shows the variable's name and its exact value and type
    • It's faster
    • It hides the value
    • It saves the value to a file
  183. What does a stack trace show?

    • The CSS that applies
    • The chain of function calls that led to the error
    • Network requests
    • Memory usage
  184. Where do you look when fetched data doesn't arrive?

    • The Elements panel
    • The Styles panel
    • The Application panel
    • The Network panel
  185. What is a conditional breakpoint?

    • A breakpoint that pauses only when an expression you give is true
    • A breakpoint inside an if statement
    • A breakpoint that runs once
    • A try...catch block
  186. Which state is a promise in while it's still waiting?

    • pending
    • fulfilled
    • rejected
    • loading
  187. What does .finally() do?

    • Runs only on success
    • Runs only on failure
    • Cancels the promise
    • Runs after the promise settles, whether it succeeded or failed
  188. Promise.all([wait(1000), wait(2000)]) takes about how long?

    • 1 second
    • 2 seconds
    • 3 seconds
    • 0 seconds
  189. Where can you use await in a normal (non-module) script?

    • Only inside async functions
    • Anywhere
    • Only in loops
    • Only with fetch
  190. How do you handle errors from an awaited promise?

    • .error()
    • if (await)
    • They can't be handled
    • try…catch
  191. How do you run two independent awaits at the same time?

    • await Promise.all([a(), b()])
    • await twice in a row
    • await a() && await b()
    • It's impossible
  192. When does a setTimeout(fn, 0) callback run?

    • Immediately
    • After exactly 0 milliseconds, interrupting other code
    • After the current code and all queued microtasks have finished
    • Never
  193. Why can't the page repaint during a long loop?

    • Loops disable the GPU
    • Rendering only happens between tasks, and the loop is still running
    • The browser is downloading
    • CSS is paused
  194. What happens to the rest of an async function after await?

    • It runs immediately
    • It's discarded
    • It moves to a new thread
    • It's scheduled to continue once the awaited promise settles
  195. How long is a "long task" according to browsers?

    • More than 50ms
    • More than 5ms
    • More than 1 second
    • More than 10 seconds
  196. Why can an endless chain of microtasks freeze the page?

    • Microtasks use more memory
    • All microtasks must finish before the next task or render, so tasks and painting never get a turn
    • Microtasks block the network
    • They run on the GPU
  197. What does response.status 200 mean?

    • Not found
    • Server error
    • Redirect
    • OK, meaning success
  198. Which HTTP method is used to create new data?

    • GET
    • POST
    • DELETE
    • HEAD
  199. Why use URLSearchParams to build query strings?

    • It correctly escapes spaces and special characters
    • It's faster
    • fetch requires it
    • It adds an API key
  200. What naming style do classes use?

    • PascalCase
    • camelCase
    • snake_case
    • kebab-case
  201. When does the constructor run?

    • When the class is defined
    • Each time you create an instance with new
    • When a method is called
    • Never automatically
  202. What makes a field private in a class?

    • The private keyword
    • An underscore _balance
    • A # prefix, like #balance
    • Declaring it in the constructor
  203. What is at the very end of a prototype chain?

    • null
    • window
    • Array.prototype
    • undefined
  204. What does Object.getPrototypeOf(obj) return?

    • A copy of obj
    • The object obj inherits from
    • obj's constructor function
    • The keys of obj
  205. What does class Dog extends Animal set up?

    • Dog.prototype's prototype is Animal.prototype
    • A copy of every Animal method on Dog
    • A global Animal variable
    • Nothing until super is called
  206. Why put methods on the prototype rather than in the constructor?

    • They run faster once
    • Constructors can't contain functions
    • It's required by new
    • All objects share one copy instead of each getting its own
  207. What does obj instanceof Fn actually check?

    • Whether obj was created on the same line
    • Whether obj has the same keys as Fn
    • Whether Fn.prototype appears anywhere in obj's prototype chain
    • Whether typeof obj is "Fn"
  208. How do you declare a generator function?

    • function gen()
    • function* gen()
    • generator gen()
    • async gen()
  209. Why can a generator use while (true) safely?

    • It pauses at every yield and only continues when asked
    • Browsers stop it after 1000 loops
    • while (true) never runs in generators
    • It runs in a separate thread
  210. Are two symbols with the same description equal?

    • Yes
    • No, every symbol is unique
    • Only in strict mode
    • Only if they're global
  211. Which of these is NOT iterable by default?

    • A string
    • A Map
    • A generator object
    • A plain object
  212. What does yield* do?

    • Hands out every value from another iterable in turn
    • Yields a star character
    • Ends the generator
    • Doubles the value
  213. What keyword shares code from a module?

    • share
    • public
    • module.out
    • export
  214. Are top-level variables in a module global?

    • No. They're private to the module unless exported
    • Yes
    • Only const ones
    • Only in Chrome
  215. What does import("./big.js") return?

    • The module synchronously
    • A Promise for the module
    • undefined
    • A string
  216. How do the page and a worker communicate?

    • By sending messages with postMessage
    • By sharing variables
    • Through the DOM
    • Through CSS
  217. How is data passed with postMessage?

    • By reference, so both sides share it
    • As a JSON string only
    • It's copied with the structured clone algorithm (or transferred, for buffers)
    • It can't pass objects
  218. What does AbortController do?

    • Stops the whole page
    • Closes a worker
    • Provides a signal that can cancel fetch requests and other async work
    • Catches errors
  219. What do service workers mainly enable?

    • Offline caching, push notifications and installable web apps
    • Faster CSS
    • Access to the DOM from workers
    • Multiple CPUs for the main thread
  220. Why pass an ArrayBuffer in a transfer list?

    • To encrypt it
    • Because buffers can't be copied
    • To share it so both sides can edit it
    • To move it to the worker instantly instead of copying it
RelaxedNo clock. Read the explanation after each answer.
Timed30 seconds per question. Great for revision.
Exam modeNo feedback until the end, then a full review.

About the JavaScript quiz

The question bank holds 220 questions drawn from 56 JavaScript lessons: 57 easy, 132 medium and 31 hard. Every time you start, the quiz picks a fresh random selection that matches your settings, so retaking it is a good way to practise. After each answer, or at the end in exam mode, you'll see why the right answer is right, and every question you miss links back to the lesson that teaches it.

What the JavaScript quiz covers