DevScrolls
40. What's the output? [[0, 1], [2,3]].reduce( (acc, cur) => { return acc.concat(cur); }, [1, 2], ); A: [0, 1, 2, 3, 1, 2] B: [6, 1, 2] C: [1, 2, 0, 1, 2, 3] D: [1, 2, 6]
Answer: C
[1, 2] is our initial value. This is the value we start with, and the value of the very first acc. During the first round, acc is [1,2], and cur is [0, 1]. We concatenate them, which results in [1, 2, 0, 1].
Then, [1, 2, 0, 1] is acc and [2, 3] is cur. We concatenate them, and get [1, 2, 0, 1, 2, 3]
[1, 2] is our initial value. This is the value we start with, and the value of the very first acc. During the first round, acc is [1,2], and cur is [0, 1]. We concatenate them, which results in [1, 2, 0, 1].
Then, [1, 2, 0, 1] is acc and [2, 3] is cur. We concatenate them, and get [1, 2, 0, 1, 2, 3]
41. What's the output?
!!null; !!' '; !!1;
!!null; !!' '; !!1;
Anonymous Poll
9%
A: false true false
64%
B: false false true
27%
C: false true true
0%
D: true true false
DevScrolls
41. What's the output?
!!null; !!' '; !!1;
!!null; !!' '; !!1;
Answer: B
null is falsy. !null returns true. !true returns false.
"" is falsy. !"" returns true. !true returns false.
1 is truthy. !1 returns false. !false returns true.
null is falsy. !null returns true. !true returns false.
"" is falsy. !"" returns true. !true returns false.
1 is truthy. !1 returns false. !false returns true.
42. What does the setInterval method return in the browser?
setInterval(() => console.log('Hi'), 1000);
setInterval(() => console.log('Hi'), 1000);
Anonymous Poll
57%
A: a unique id
14%
B: the amount of milliseconds specified
29%
C: the passed function
0%
D: undefined
DevScrolls
42. What does the setInterval method return in the browser?
setInterval(() => console.log('Hi'), 1000);
setInterval(() => console.log('Hi'), 1000);
Answer: A
It returns a unique id. This id can be used to clear that interval with the clearInterval() function.
It returns a unique id. This id can be used to clear that interval with the clearInterval() function.
43. What does this return?
[...'Lydia'];
[...'Lydia'];
Anonymous Poll
64%
A: ["L", "y", "d", "i", "a"]
29%
B: ["Lydia"]
0%
C: [[], "Lydia"]
7%
D: [["L", "y", "d", "i", "a"]]
DevScrolls
43. What does this return?
[...'Lydia'];
[...'Lydia'];
Answer: A
A string is an iterable. The spread operator maps every character of an iterable to one element.
A string is an iterable. The spread operator maps every character of an iterable to one element.
44. What's the output?
function* generator(i) {
yield i;
yield i * 2;
}
const gen = generator(10); console.log(gen.next().value); console.log(gen.next().value);
DevScrolls
What's output?
Answer: C
Regular functions cannot be stopped mid-way after invocation. However, a generator function can be "stopped" midway, and later continue from where it stopped. Every time a generator function encounters a yield keyword, the function yields the value specified after it. Note that the generator function in that case doesn’t return the value, it yields the value.
First, we initialize the generator function with i equal to 10. We invoke the generator function using the next() method. The first time we invoke the generator function, i is equal to 10. It encounters the first yield keyword: it yields the value of i. The generator is now "paused", and 10 gets logged.
Then, we invoke the function again with the next() method. It starts to continue where it stopped previously, still with i equal to 10. Now, it encounters the next yield keyword, and yields i * 2. i is equal to 10, so it returns 10 * 2, which is 20. This results in 10, 20.
Regular functions cannot be stopped mid-way after invocation. However, a generator function can be "stopped" midway, and later continue from where it stopped. Every time a generator function encounters a yield keyword, the function yields the value specified after it. Note that the generator function in that case doesn’t return the value, it yields the value.
First, we initialize the generator function with i equal to 10. We invoke the generator function using the next() method. The first time we invoke the generator function, i is equal to 10. It encounters the first yield keyword: it yields the value of i. The generator is now "paused", and 10 gets logged.
Then, we invoke the function again with the next() method. It starts to continue where it stopped previously, still with i equal to 10. Now, it encounters the next yield keyword, and yields i * 2. i is equal to 10, so it returns 10 * 2, which is 20. This results in 10, 20.
45. What does this return?
const firstPromise = new Promise((res, rej) => {
setTimeout(res, 500, 'one'); });
const secondPromise = new Promise((res, rej) => {
setTimeout(res, 100, 'two'); }); Promise.race([firstPromise, secondPromise]).then(res => console.log(res));
DevScrolls
Whats the output?
Answer: B
When we pass multiple promises to the Promise.race method, it resolves/rejects the first promise that resolves/rejects. To the setTimeout method, we pass a timer: 500ms for the first promise (firstPromise), and 100ms for the second promise (secondPromise). This means that the secondPromise resolves first with the value of 'two'. res now holds the value of 'two', which gets logged.
When we pass multiple promises to the Promise.race method, it resolves/rejects the first promise that resolves/rejects. To the setTimeout method, we pass a timer: 500ms for the first promise (firstPromise), and 100ms for the second promise (secondPromise). This means that the secondPromise resolves first with the value of 'two'. res now holds the value of 'two', which gets logged.
46. What's the output?
let person = { name: 'Lydia' }; const members = [person]; person = null; console.log(members);
let person = { name: 'Lydia' }; const members = [person]; person = null; console.log(members);
Anonymous Poll
26%
A: null
24%
B: [null]
12%
C: [{}]
38%
D: [{ name: "Lydia" }]
DevScrolls
46. What's the output?
let person = { name: 'Lydia' }; const members = [person]; person = null; console.log(members);
let person = { name: 'Lydia' }; const members = [person]; person = null; console.log(members);
Answer: D
First, we declare a variable person with the value of an object that has a name property.

Then, we declare a variable called members. We set the first element of that array equal to the value of the person variable. Objects interact by reference when setting them equal to each other. When you assign a reference from one variable to another, you make a copy of that reference. (note that they don't have the same reference!)

Then, we set the variable person equal to null.

We are only modifying the value of the person variable, and not the first element in the array, since that element has a different (copied) reference to the object. The first element in members still holds its reference to the original object. When we log the members array, the first element still holds the value of the object, which gets logged.
First, we declare a variable person with the value of an object that has a name property.

Then, we declare a variable called members. We set the first element of that array equal to the value of the person variable. Objects interact by reference when setting them equal to each other. When you assign a reference from one variable to another, you make a copy of that reference. (note that they don't have the same reference!)

Then, we set the variable person equal to null.

We are only modifying the value of the person variable, and not the first element in the array, since that element has a different (copied) reference to the object. The first element in members still holds its reference to the original object. When we log the members array, the first element still holds the value of the object, which gets logged.
47. What's the output?
const person = { name: 'Lydia', age: 21, }; for (const item in person) { console.log(item); }
const person = { name: 'Lydia', age: 21, }; for (const item in person) { console.log(item); }
Anonymous Poll
38%
A: { name: "Lydia" }, { age: 21 }
21%
B: "name", "age"
33%
C: "Lydia", 21
8%
D: ["name", "Lydia"], ["age", 21]
DevScrolls
47. What's the output?
const person = { name: 'Lydia', age: 21, }; for (const item in person) { console.log(item); }
const person = { name: 'Lydia', age: 21, }; for (const item in person) { console.log(item); }
Answer: B
With a for-in loop, we can iterate through object keys, in this case name and age. Under the hood, object keys are strings (if they're not a Symbol). On every loop, we set the value of item equal to the current key it’s iterating over. First, item is equal to name, and gets logged. Then, item is equal to age, which gets logged.
With a for-in loop, we can iterate through object keys, in this case name and age. Under the hood, object keys are strings (if they're not a Symbol). On every loop, we set the value of item equal to the current key it’s iterating over. First, item is equal to name, and gets logged. Then, item is equal to age, which gets logged.
48. What's the output?
console.log(3 + 4 + '5');
console.log(3 + 4 + '5');
Anonymous Poll
13%
A: "345"
67%
B: "75"
13%
C: 12
7%
D: "12"
DevScrolls
48. What's the output?
console.log(3 + 4 + '5');
console.log(3 + 4 + '5');
Answer: B
Operator associativity is the order in which the compiler evaluates the expressions, either left-to-right or right-to-left. This only happens if all operators have the same precedence. We only have one type of operator: +. For addition, the associativity is left-to-right.
3 + 4 gets evaluated first. This results in the number 7.
7 + '5' results in "75" because of coercion. JavaScript converts the number 7 into a string, see question 15. We can concatenate two strings using the +operator. "7" + "5" results in "75".
Operator associativity is the order in which the compiler evaluates the expressions, either left-to-right or right-to-left. This only happens if all operators have the same precedence. We only have one type of operator: +. For addition, the associativity is left-to-right.
3 + 4 gets evaluated first. This results in the number 7.
7 + '5' results in "75" because of coercion. JavaScript converts the number 7 into a string, see question 15. We can concatenate two strings using the +operator. "7" + "5" results in "75".