Are you ready?

1 questions to solve.

Instructions
  1. This quiz goes to full-screen once you press the Start button, or any Next button after exiting the quiz window.
  2. At the end of the quiz, you are able to review all the questions that you answered wrong and see their explanations.
What does the iterator protocol say?
According to the iterable protocol, an iterable object is one with an @iterator() method available. True or false?
Does the object o shown below conform to the iterable protocol?
var o = {
    a: 10,
    b: 30
}
Clearly NO! The reason is because o doesn't have an @iterator() method available on it. For more info, refer to JavaScript Iterables.
Arrays and strings are iterables, by default. True or false?
One can indeed use arrays and strings in a for...of loop which justifies the fact that arrays and strings are iterable by default. For more info please refer to JavaScript Iterables.
What will the following code log?
Number.prototype[Symbol.iterator] = function() {
    return this.toString()[Symbol.iterator]();
}

var num = 13756, arr = [];

for (var n of num) {
    arr.push(n);
}

console.log(arr.join("-"));
To fully understand the code here, please refer JavaScript Iterables.
What will the following code log?
var num = 13756, arr = [];

for (var n of num) {
    arr.push(n);
}

console.log(arr.join("-"));
Since numbers in JavaScript are NOT iterable by default, using them in a for...of loop will lead to an error. Refer to JavaScript Iterables for more info.
The for...of loop requires that you pass it an iterable object. True or false?
Internally, a for...of loop invokes the @iterator() method on the provided object - which means it operates on iterable objects only. This goes with choice (A). For more info please refer to JavaScript Iterables.
According to the iterator protocol, the done property of the object returned by next() is of what type?
done is of type Boolean, and it indicates whether the iterator has been consumed completely or not. Refer to JavaScript Iterators for more info.
What will the following code log?
var arr = [1, 3, 5];
var iter = arr[Symbol.iterator]();

console.log(iter.next());
iter.next() returns the object {value: 1, done: false}. To understand where these properties come from, please refer to JavaScript Iterators.
Are numbers in JavaScript iterable, by default?
Clearly NO! We can NOT iterate over numbers using a for...of loop, which is clearly shown in JavaScript Iterables.
What will the following code log?
var arr = [1, 3, 5];
var iter = arr[Symbol.iterator]();

iter.next();
iter.next();
iter.next();

console.log(iter.next());
To understand this code please refer to JavaScript Iterators.