How does the for...of loop handle objects by default?
- It iterates over the properties.
- It throws an error.
- It iterates over the values.
- It iterates over the keys.
The for...of loop in JavaScript is used for iterating over iterable objects like arrays, strings, maps, and sets. By default, it iterates over the values of an iterable, making it a convenient choice for iterating through the elements of an array or the characters of a string, for example. It doesn't work with plain objects (non-iterable) and would require additional steps or methods to iterate over object properties.
Loading...
Related Quiz
- What is the drawback of using "inheritance" through the prototype chain?
- What is lexical scoping in JavaScript?
- The method getElementById selects an element using its ______.
- To prevent variables from being added to the global object, it is common to use a(n) _______ function expression.
- Which of the following JavaScript methods can create a new HTML element?