JavaScript final quiz

  • Admin
  • 1 min read

Ten mixed questions on events, async code, modules, accessibility and the capstone.

JavaScript

JavaScript final quiz

10 questions, instant feedback

Question 1 of 10
Question 1 of 10 Which statement about JavaScript in the browser is true?
Why this is the answer

The browser runs JavaScript with access to the DOM, events and browser APIs. The same language also runs on servers via Node.

Question 2 of 10
Question 2 of 10 Why should a script that reads the DOM be loaded with defer or placed at the end of body?
Why this is the answer

Scripts in the head run before the body is parsed. defer waits until parsing finishes, so querySelector finds the elements.

Question 3 of 10
Question 3 of 10 A form handler throws on a missing field. What is the best response?
Why this is the answer

Specific, visible feedback near the field is usable and announced. Reloading loses everything the person typed.

Question 4 of 10
Question 4 of 10 Which is the safest way to insert user-provided text?
Why this is the answer

textContent cannot introduce markup or scripts. innerHTML with untrusted text is a cross-site scripting risk.

Question 5 of 10
Question 5 of 10 What does event delegation rely on?
Why this is the answer

A listener on a parent receives events from children as they bubble, so one handler covers dynamically added items.

Question 6 of 10
Question 6 of 10 Which code reads a stored object safely?
Why this is the answer

Storage returns a string or null. Parsing with a fallback array handles the first run, and a try/catch handles corrupted data.

Question 7 of 10
Question 7 of 10 Why wrap JSON.parse in try...catch when reading saved data?
Why this is the answer

Saved data can be truncated or hand-edited. A parse error should not break the whole app.

Question 8 of 10
Question 8 of 10 What is the main benefit of splitting code into modules?
Why this is the answer

Imports and exports make dependencies visible, and each module can be tested or replaced on its own.

Question 9 of 10
Question 9 of 10 Which practice keeps a to-do app usable with a keyboard?
Why this is the answer

Native controls handle Enter, Space and focus. Visible focus is required for anyone navigating without a mouse.

Question 10 of 10
Question 10 of 10 When should state be written to localStorage in a to-do app?
Why this is the answer

Saving after each successful change means a crash or closed tab loses nothing. Saving only on unload is unreliable.

Your answers stay in this browser. Nothing is sent to a server.