CodeYourFuture / syllabus-archive

[ARCHIVED] Please use https://github.com/CodeYourFuture/syllabus
https://codeyourfuture.github.io/syllabus-master
74 stars 116 forks source link

Fix description of what `.querySelectorAll` returns #466

Closed EmilePW closed 4 years ago

EmilePW commented 4 years ago

What does this change?

Module: JS2 Week(s): 2

Description

I've changed the description of what .querySelectorAll returns to be slightly more accurate - it previously said that it returns an array when it actually returns an array-like NodeList which doesn't implement most of the array methods. I hope now it isn't too confusing by introducing an extra concept? My worry was that students might start trying to use .map, etc. on a NodeList and be confused when that fails.

Rendered version

Who needs to know about this?

@ChrisOwen101

illicitonion commented 4 years ago

This looks great, thanks :) It may also be worth mentioning something like:

If you want to use a NodeList like an Array (e.g. call .map on it), you can turn it into an Array like this:

let elementArray = Array.from(document.querySelectorAll("div"));

Then elementArray will be an Array containing each of the DOM elements.

EmilePW commented 4 years ago

Thanks @illicitonion, that's a good point - I've added an Array.from example in too.