32. JavaScript Quiz

Test yourself

Choose an answer for each question. You get feedback straight away, and your best score is saved on this device.

Which HTML element holds JavaScript code?

  • <js>
  • <code>
  • <script>
  • <javascript>

Which keyword declares a value that cannot be reassigned?

  • let
  • const
  • var
  • static

What does "5" + 2 produce?

  • 7
  • NaN
  • An error
  • "52"

Which operator compares both value and type?

  • ===
  • ==
  • =
  • =>

What is the index of the first item in an array?

  • 1
  • 0
  • -1
  • It depends on the array

Which array method returns a new array containing only the items that pass a test?

  • map()
  • reduce()
  • filter()
  • find()

What does a function return if it has no return statement?

  • undefined
  • null
  • 0
  • An empty string

Which is the safest way to put text typed by a visitor into the page?

  • element.innerHTML = text
  • document.write(text)
  • eval(text)
  • element.textContent = text

Which method returns only the first element matching a CSS selector?

  • querySelectorAll()
  • querySelector()
  • getElementsByTagName()
  • findElement()

What does event.preventDefault() do on a form’s submit event?

  • Deletes the form
  • Checks the form is valid
  • Stops the browser’s normal submit and page reload
  • Sends the form twice

Which method turns an object into JSON text?

  • JSON.stringify()
  • JSON.parse()
  • JSON.toObject()
  • Object.toJSON()

A fetch() request returns a 404 response. What happens to the promise?

  • It is rejected automatically
  • It still resolves, so you must check response.ok
  • The page reloads
  • It retries three times

What next?

You have finished the JavaScript course. Continue with the PHP Tutorial to learn how websites work on the server side.

Scroll to Top