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.
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
JavaScript and Java are the same language.
- True
- False
In what order do statements run?
- Bottom to top
- Shortest first
- Randomly
- Top to bottom, one after another
What does
console.log(3 + 4)print?- 34
- 7
- 3 + 4
- Nothing
What file extension do JavaScript files use?
- .js
- .java
- .jsx only
- .script
What's the difference between
asyncanddefer?- There is none
deferruns in order after parsing;asyncruns as soon as it downloads, in any orderasyncis faster in all casesdeferonly works on inline scripts
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"
Which method prints a red error message?
- console.error
- console.log
- console.red
- console.fail
What does
console.log("a", "b")print?- ab
- "a", "b"
- a b
- a,b
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
Which keyword should you use by default?
- var
- const
- let
- variable
What is the value of a variable declared with
let x;and nothing else?- 0
- null
- ""
- undefined
Are
scoreandScorethe same variable?- Yes
- No, because JavaScript is case-sensitive
- Only if declared with var
- Only inside functions
Which of these is a boolean?
- "true"
- 0
- "no"
- false
What's the difference between
undefinedandnull?undefinedmeans no value was assigned;nullis deliberately empty- They're identical
nullis a numberundefinedis a string
How do you reliably check if a value is an array?
typeof x === "array"Array.isArray(x)x.type === "array"x instanceof List
What does
x++do?- Doubles x
- Adds 1 to x
- Adds x to itself
- Nothing
What is
true && false?- false
- true
- undefined
- An error
What does
const msg = 7 > 5 ? "yes" : "no";store?- "no"
- true
- "yes"
- 7
What is
"2" * "3"?- "23"
- "6"
- NaN
- 6
What is
"hello".length?- 4
- 6
- 5
- "hello"
Which quote type allows
${variables}and multiple lines?- "double"
- 'single'
backticks- All of them
What does
"\n"represent?- The letter n
- A new line
- A null value
- A tab
What does
"Hi".repeat(3)return?- "HiHiHi"
- "Hi3"
- ["Hi", "Hi", "Hi"]
- "Hi Hi Hi"
What does
"banana".indexOf("z")return?- 0
- null
- -1
- false
What is
"one two three".split(" ")?- ["one", "two", "three"]
- "onetwothree"
- ["o", "n", "e", …]
- 3
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
What does
parseInt("25px")return?- NaN
- 25
- "25"
- 25px
What type does
(5).toFixed(2)return?- number
- boolean
- string
- NaN
What does
0.1 + 0.2 === 0.3evaluate to?- false
- true
- NaN
- An error
What does
10 >= 10return?- false
- true
- 10
- undefined
What does
"3" === 3return?- true
- NaN
- false
- An error
How many falsy values are there in JavaScript?
- 6 (false, 0, "", null, undefined, NaN)
- 2
- 4
- Every value is falsy
What does
!truereturn?- true
- null
- An error
- false
What does
null || "x"return?- "x"
- null
- true
- false
When should you use ?? instead of ||?
- Always
- Never
- Only with strings
- When 0, "" or false are valid values that shouldn't be replaced
What does
x > 10 ? "big" : "small"return when x is 4?- "big"
- true
- "small"
- 4
What does
false && expensiveCheck()do?- Runs expensiveCheck and returns false
- Returns false without calling expensiveCheck
- Throws an error
- Returns undefined
When does the
elseblock run?- Always
- When the first condition is true
- Never
- When all previous conditions are false
How many blocks can run in one if/else if/else chain?
- All whose conditions are true
- Exactly two
- At most one
- Unlimited
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
What does
defaultdo in a switch?- Runs when no case matches
- Runs first
- Sets a default value
- Is required
Which comparison does switch use?
- ==
- >
- It depends on the type
- ===
How do you make two cases run the same code?
case "a" || "b":case ["a", "b"]:- Write
case "a":andcase "b":one after the other, then the code - It's not possible
Which loop is simplest for going through every item of an array?
- for…in
- while
- switch
- for…of
What does
continuedo inside a loop?- Stops the loop
- Restarts the loop from the beginning
- Skips to the next iteration
- Pauses for a second
For an array of length 5, what is the last valid index?
- 4
- 5
- 6
- -1
When does a while loop stop?
- When its condition becomes false (or on break)
- After 10 laps
- When the page reloads
- Never
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
What does
while (true) { … }need to avoid running forever?- continue
- A semicolon
- Nothing, because it stops automatically
- A break inside it
Which loop is best for the values of an array?
- for...in
- for...of
- do...while
- switch
What does continue do?
- Skips to the next iteration
- Ends the program
- Restarts the loop from the beginning
- Exits all loops
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())
Which of these is NOT iterable with for...of?
- A plain object
- A string
- A Set
- A NodeList
In nested loops, what does a plain break affect?
- All loops
- The outer loop
- Only the innermost loop
- Nothing
How do you call a function named
start?- call start
- start
- start()
- function start()
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
What does a function return if it has no
returnstatement?- undefined
- null
- 0
- An error
What happens to code written after
returnin the same block?- It runs after the return
- It never runs
- It runs before the return
- It causes a syntax error
Which is a valid arrow function?
const f = => 1;const f = () -> 1;const f = () => 1;const f = function => 1;
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
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
- Arrows don't have their own
Which keyword ignores block scope and should be avoided?
- let
- const
- var
- function
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
What happens if you use a
letvariable before its declaration line?- ReferenceError (temporal dead zone)
- It's undefined
- It's 0
- It works normally
Which should you use by default for new variables?
- const
- var
- let
- global
Which can be called before the line it's defined on?
- const save = () => {}
- const save = function () {}
- function save() {}
- class Save {}
What does "use strict" do to an assignment to an undeclared variable?
- Creates a global
- Ignores it
- Converts it to let
- Throws a ReferenceError
Are JavaScript modules in strict mode?
- Yes, automatically
- Only with "use strict"
- No, never
- Only in Node.js
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
Which is a higher-order function?
- Math.PI
- array.map
- console
- "text".length
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
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
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
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
What is recursion?
- A loop inside a loop
- A function with many arguments
- Repeating code by copying it
- A function calling itself
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
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
Can every recursive function be written as a loop?
- Yes, possibly with your own stack array
- No, never
- Only factorial
- Only in Python
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
What is the index of the first item in an array?
- 0
- 1
- -1
- It depends
Which method removes the last item and returns it?
- shift()
- slice()
- remove()
- pop()
What does
["a", "b"].indexOf("z")return?- 0
- null
- -1
- false
Which method copies part of an array without changing the original?
- splice
- pop
- shift
- slice
Does
mapchange the original array?- Yes
- No, it returns a new array
- Only for numbers
- Only if you use const
What does
[1, 2, 3].filter(n => n > 5)return?- []
- undefined
- null
- false
What's the difference between
sort()andtoSorted()?- toSorted is alphabetical only
- There's no difference
- sort is newer
- sort changes the original array; toSorted returns a sorted copy
In
reduce((acc, n) => acc + n, 0), what isacc?- The current index
- The original array
- The running result (accumulator) from the previous step
- Always 0
What does [2, 10, 1].sort() return?
- [1, 2, 10]
- [10, 2, 1]
- An error
- [1, 10, 2]
What should a compare function return when a should come first?
- A positive number
- true
- Zero
- A negative number
What does every() return for an empty array?
- false
- true
- undefined
- An error
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
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
What is a property?
- A function
- A key and value pair in an object
- An array index
- A CSS rule
What does
Object.keys({ a: 1, b: 2 })return?- [1, 2]
- 2
- { a, b }
- ["a", "b"]
When must you use bracket notation?
- When the key is stored in a variable or contains spaces/dashes
- Always
- For numbers only
- Never
What does Object.values({ a: 1, b: 2 }) return?
- ["a", "b"]
- [1, 2]
- [["a", 1], ["b", 2]]
- 2
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
Is Object.freeze deep?
- No, nested objects can still change
- Yes, every level
- Only for arrays
- Only in strict mode
What does JSON.parse(JSON.stringify(obj)) lose?
- Strings
- Numbers
- Nothing
- Functions, undefined values, and Date objects (which become strings)
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
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
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
Which method takes arguments as an array?
- call
- apply
- bind
- map
In a normal function event listener, what is this?
- The event object
- The window, always
- The element the listener is attached to
- undefined
What is this inside a plain function call in strict mode?
- window
- The function itself
- null
- undefined
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
What does
{ ...a, ...b }do when both have a keyid?- Throws an error
- Keeps b's id (the later one wins)
- Keeps a's id
- Creates an array of both ids
In
function f(...args), what isargs?- The first argument
- A string
- An object
- An array of all the arguments
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
How do you get the number of entries in a Map?
- map.length
- map.count()
- map.size
- Object.keys(map).length
What order does a Map keep its entries in?
- Alphabetical
- Random
- By value
- The order they were added
How do you turn a Map into a plain object?
- JSON.parse(map)
- Object.fromEntries(map)
- map.toObject()
- { ...map }
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
What does new Date() give you?
- 1 January 1970
- An empty date
- The current date and time
- An error
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
Which date string format is safest to parse?
- "03/14/2026"
- "2026-03-14"
- "14 March 26"
- "March the 14th"
How do you add 7 days to date d?
- d + 7
- d.addDays(7)
- d.setDate(d.getDate() + 7)
- d.getDate() + 7
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
What does \d match?
- A letter
- A digit
- A space
- A dollar sign
What does the g flag do?
- Makes the match greedy
- Groups the pattern
- Ignores case
- Finds all matches instead of only the first
In "2026-03".replace(/(\d+)-(\d+)/, "$2/$1"), what is the result?
- "03/2026"
- "2026/03"
- "$2/$1"
- "03-2026"
Which quantifier makes something optional?
- +
- ?
- *
- {2}
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"
What does DOM stand for?
- Document Object Model
- Data Object Manager
- Digital Output Mode
- Document Order Map
Which method do NodeLists not have?
- forEach
- map
- length
- item
How do you search only inside a specific element
panel?document.querySelector(panel, "p")panel.find("p")panel.querySelector("p")document.panel("p")
Which method creates a new element?
- document.newElement("p")
- document.make("p")
- new Element("p")
- document.createElement("p")
How do you read
data-price="12"from an element?- el.price
- el.data("price")
- el.attributes.price
- el.dataset.price
In JavaScript, what is the CSS property
font-sizecalled onel.style?- fontSize
- font-size
- FontSize
- font_size
Which method adds content at the start of a parent?
- prepend
- append
- before
- after
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
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
What is a template element for?
- Styling forms
- Loading scripts
- Defining CSS variables
- Holding inert markup you can clone and fill with JavaScript
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
Which method attaches an event handler?
- el.onEvent()
- el.listen()
- el.handle()
- el.addEventListener()
What is
event.target?- The function that handles the event
- The element the event actually happened on
- The parent element
- The window
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
Which method stops a link from navigating?
- stopPropagation()
- preventDefault()
- return false in addEventListener
- removeEventListener()
Which of these events does NOT bubble?
- focus
- click
- input
- keydown
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
How do you check whether a click happened outside a menu?
- !menu.contains(event.target)
- event.target === document
- event.outside
- menu.isClicked === false
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
Which event should you listen for to handle a form being sent?
- submit
- click
- change
- send
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
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
Which event fires on every keystroke in a text field?
- input
- change
- submit
- blur
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
What unit is the delay in setTimeout?
- Seconds
- Minutes
- Frames
- Milliseconds
Does
setTimeoutpause the rest of your code?- No. It schedules the function and the code continues immediately
- Yes
- Only for long delays
- Only in loops
What is debouncing?
- Running code faster
- Waiting until events stop for a moment before running code
- Repeating code forever
- Removing bugs automatically
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
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
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
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
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
Does localStorage data survive a page refresh?
- No
- Only for 1 hour
- Yes
- Only in Chrome
What's the difference between localStorage and sessionStorage?
- sessionStorage is cleared when the tab closes
- sessionStorage is bigger
- localStorage is server-side
- No difference
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
What does JSON stand for?
- Java Standard Object Notation
- JavaScript Object Notation
- JavaScript Online Network
- JSON Simple Object Name
What type does
JSON.stringify([1, 2])return?- array
- object
- string
- number
Can JSON contain functions?
- Yes
- No
- Only arrow functions
- Only in arrays
What is location.pathname for https://site.com/blog/post?id=3?
- https://site.com
- /blog/post
- ?id=3
- post
Which event fires when the user presses the back button after pushState?
- load
- hashchange only
- unload
- popstate
What is the global object in the browser?
- document
- navigator
- window
- global
Which API copies text to the clipboard?
- document.copy()
- navigator.clipboard.writeText(text)
- window.clipboard = text
- location.copy(text)
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
What does matchMedia("(max-width: 600px)").matches return?
- The screen width
- A CSS rule
- An event
- true or false
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
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
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
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
Which element do you draw on with the Canvas API?
- svg
- img
- canvas
- div
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)
How do you stop a requestAnimationFrame loop?
- clearInterval(id)
- cancelAnimationFrame(id)
- stopAnimation()
- return false
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
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
When does the
finallyblock run?- Always
- Only if there was an error
- Only if there was no error
- Never
Which error do you get from
null.length?- ReferenceError
- SyntaxError
- RangeError
- TypeError
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
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
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
What does a stack trace show?
- The CSS that applies
- The chain of function calls that led to the error
- Network requests
- Memory usage
Where do you look when fetched data doesn't arrive?
- The Elements panel
- The Styles panel
- The Application panel
- The Network panel
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
Which state is a promise in while it's still waiting?
- pending
- fulfilled
- rejected
- loading
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
Promise.all([wait(1000), wait(2000)])takes about how long?- 1 second
- 2 seconds
- 3 seconds
- 0 seconds
Where can you use
awaitin a normal (non-module) script?- Only inside async functions
- Anywhere
- Only in loops
- Only with fetch
How do you handle errors from an awaited promise?
- .error()
- if (await)
- They can't be handled
- try…catch
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
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
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
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
How long is a "long task" according to browsers?
- More than 50ms
- More than 5ms
- More than 1 second
- More than 10 seconds
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
What does
response.status200 mean?- Not found
- Server error
- Redirect
- OK, meaning success
Which HTTP method is used to create new data?
- GET
- POST
- DELETE
- HEAD
Why use
URLSearchParamsto build query strings?- It correctly escapes spaces and special characters
- It's faster
- fetch requires it
- It adds an API key
What naming style do classes use?
- PascalCase
- camelCase
- snake_case
- kebab-case
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
What makes a field private in a class?
- The
privatekeyword - An underscore
_balance - A
#prefix, like#balance - Declaring it in the constructor
- The
What is at the very end of a prototype chain?
- null
- window
- Array.prototype
- undefined
What does Object.getPrototypeOf(obj) return?
- A copy of obj
- The object obj inherits from
- obj's constructor function
- The keys of obj
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
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
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"
How do you declare a generator function?
- function gen()
- function* gen()
- generator gen()
- async gen()
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
Are two symbols with the same description equal?
- Yes
- No, every symbol is unique
- Only in strict mode
- Only if they're global
Which of these is NOT iterable by default?
- A string
- A Map
- A generator object
- A plain object
What does yield* do?
- Hands out every value from another iterable in turn
- Yields a star character
- Ends the generator
- Doubles the value
What keyword shares code from a module?
- share
- public
- module.out
- export
Are top-level variables in a module global?
- No. They're private to the module unless exported
- Yes
- Only const ones
- Only in Chrome
What does
import("./big.js")return?- The module synchronously
- A Promise for the module
- undefined
- A string
How do the page and a worker communicate?
- By sending messages with postMessage
- By sharing variables
- Through the DOM
- Through CSS
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
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
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
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
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
Basics
Logic & Functions
- 12JavaScript if…else
- 13JavaScript switch
- 14JavaScript for Loops
- 15JavaScript while Loops
- 16for...of, for...in, break and continue
- 17JavaScript Functions
- 18JavaScript Arrow Functions
- 19JavaScript Scope
- 20Hoisting, var vs let vs const and Strict Mode
- 21Callbacks and Higher-Order Functions
- 22Recursion in JavaScript
Data Structures
- 23JavaScript Arrays
- 24JavaScript Array Methods
- 25Sorting and Searching Arrays
- 26JavaScript Objects
- 27Object Methods, Getters, Setters and Copying
- 28The this Keyword, call(), apply() and bind()
- 29Destructuring, Spread & Rest
- 30Sets and Maps in JavaScript
- 31Dates, Times and Intl Formatting
- 32Regular Expressions (Regex) in JavaScript
DOM & Browser
- 33Selecting DOM Elements
- 34Changing the Page (DOM Manipulation)
- 35Creating, Removing and Traversing Elements
- 36JavaScript Events
- 37Event Bubbling, Capturing and Delegation
- 38Working with Forms in JavaScript
- 39JavaScript Timers
- 40Debounce and Throttle
- 41JavaScript localStorage
- 42JavaScript JSON
- 43Browser APIs: window, location, history and Observers
- 44Responsive JavaScript: matchMedia, Resize and ResizeObserver
- 45Drawing and Animating with Canvas
Advanced
- 46JavaScript Errors & Debugging
- 47Debugging JavaScript with the Console and DevTools
- 48JavaScript Promises
- 49JavaScript async/await
- 50The JavaScript Event Loop
- 51JavaScript Fetch API
- 52JavaScript Classes
- 53Prototypes and Prototype Inheritance
- 54Iterators, Generators and Symbols
- 55JavaScript Modules
- 56Web Workers and Background APIs