JavaScript Flashcards
7 cards from real Web Development practice questions. Tap to flip, then mark Knew It or Still Learning โ missed cards come back until you master them.
Read the first 7 JavaScript flashcards as text
What is the output of `console.log([] + [])`?
Answer: ""
Both arrays are coerced to empty strings, and string concatenation produces an empty string `""`.
Which of the following correctly uses destructuring to extract values from an object?
Answer: const {name, age} = person;
Object destructuring uses curly braces to extract named properties into variables.
What does `event.stopPropagation()` do in JavaScript?
Answer: Stops the event from bubbling up to parent elements
`stopPropagation()` halts the event from traveling up (or down) the DOM tree after the current handler executes.
What is a JavaScript generator function?
Answer: A function declared with `function*` that can pause and resume execution using `yield`
Generator functions use `function*` syntax and `yield` to produce a sequence of values on demand, pausing execution between yields.
What does `localStorage.setItem('key', value)` do when `value` is an object?
Answer: Stores `[object Object]` as a string
`localStorage` only stores strings, so objects are coerced via `.toString()`, producing `[object Object]` unless you manually call `JSON.stringify()`.
Which method is used to attach an event handler to a DOM element in modern JavaScript?
Answer: element.addEventListener()
`addEventListener()` is the standard method to attach event handlers, allowing multiple handlers on the same element.
What is the purpose of the `WeakMap` in JavaScript?
Answer: A Map whose keys must be objects and are held weakly so they can be garbage collected
`WeakMap` keys must be objects and are weakly referenced, meaning they don't prevent garbage collection when no other references exist.
How this page was made: written with AI tools. We have not yet matched this exam's facts to an official source, so confirm fees, dates and rules with the exam body. Not reviewed by a subject-matter expert. Editorial policy