DevScrolls
65. What's the output?
[1, 2, 3, 4].reduce((x, y) => console.log(x, y));
[1, 2, 3, 4].reduce((x, y) => console.log(x, y));
Answer: D
The first argument that the reduce method receives is the accumulator, x in this case. The second argument is the current value, y. With the reduce method, we execute a callback function on every element in the array, which could ultimately result in one single value.
In this example, we are not returning any values, we are simply logging the values of the accumulator and the current value.
The value of the accumulator is equal to the previously returned value of the callback function. If you don't pass the optional initialValue argument to the reduce method, the accumulator is equal to the first element on the first call.
On the first call, the accumulator (x) is 1, and the current value (y) is 2. We don't return from the callback function, we log the accumulator and current value: 1 and 2 get logged.
If you don't return a value from a function, it returns undefined. On the next call, the accumulator is undefined, and the current value is 3. undefined and 3 get logged.
On the fourth call, we again don't return from the callback function. The accumulator is again undefined, and the current value is 4. undefined and 4 get logged.
The first argument that the reduce method receives is the accumulator, x in this case. The second argument is the current value, y. With the reduce method, we execute a callback function on every element in the array, which could ultimately result in one single value.
In this example, we are not returning any values, we are simply logging the values of the accumulator and the current value.
The value of the accumulator is equal to the previously returned value of the callback function. If you don't pass the optional initialValue argument to the reduce method, the accumulator is equal to the first element on the first call.
On the first call, the accumulator (x) is 1, and the current value (y) is 2. We don't return from the callback function, we log the accumulator and current value: 1 and 2 get logged.
If you don't return a value from a function, it returns undefined. On the next call, the accumulator is undefined, and the current value is 3. undefined and 3 get logged.
On the fourth call, we again don't return from the callback function. The accumulator is again undefined, and the current value is 4. undefined and 4 get logged.
67. What's the output?
// index.js
console.log('running index.js');
import { sum } from './sum.js';
console.log(sum(1, 2));
// sum.js
console.log('running sum.js');
export const sum = (a, b) => a + b;
DevScrolls
67. What's the output? // index.js console.log('running index.js'); import { sum } from './sum.js'; console.log(sum(1, 2)); // sum.js console.log('running sum.js'); export const sum = (a, b) => a + b;
68. What's the output?
console.log(Number(2) === Number(2)); console.log(Boolean(false) === Boolean(false)); console.log(Symbol('foo') === Symbol('foo'));
console.log(Number(2) === Number(2)); console.log(Boolean(false) === Boolean(false)); console.log(Symbol('foo') === Symbol('foo'));
Anonymous Poll
35%
A: true, true, false
13%
B: false, true, false
4%
C: true, false, true
48%
D: true, true, true
❤1
69. What's the output?
const name = 'Lydia Hallie'; console.log(name.padStart(13)); console.log(name.padStart(2));
const name = 'Lydia Hallie'; console.log(name.padStart(13)); console.log(name.padStart(2));
Anonymous Poll
21%
A: "Lydia Hallie", "Lydia Hallie"
46%
B: " Lydia Hallie", " Lydia Hallie" ("[13x whitespace]Lydia Hallie", "[2x whitespace]Lydia Hallie")
8%
C: " Lydia Hallie", "Lydia Hallie" ("[1x whitespace]Lydia Hallie", "Lydia Hallie")
25%
D: "Lydia Hallie", "Lyd"
70. What's the output?
console.log('🥑' + '💻');
console.log('🥑' + '💻');
Anonymous Poll
65%
A: "🥑💻"
0%
B: 257548
14%
C: A string containing their code points
22%
D: Error
DevScrolls
69. What's the output?
const name = 'Lydia Hallie'; console.log(name.padStart(13)); console.log(name.padStart(2));
const name = 'Lydia Hallie'; console.log(name.padStart(13)); console.log(name.padStart(2));
Answer: C
With the padStart method, we can add padding to the beginning of a string. The value passed to this method is the total length of the string together with the padding. The string "Lydia Hallie" has a length of 12. name.padStart(13) inserts 1 space at the start of the string, because 12 + 1 is 13.
If the argument passed to the padStart method is smaller than the length of the array, no padding will be added.
With the padStart method, we can add padding to the beginning of a string. The value passed to this method is the total length of the string together with the padding. The string "Lydia Hallie" has a length of 12. name.padStart(13) inserts 1 space at the start of the string, because 12 + 1 is 13.
If the argument passed to the padStart method is smaller than the length of the array, no padding will be added.
DevScrolls
70. What's the output?
console.log('🥑' + '💻');
console.log('🥑' + '💻');
Answer: A
With the + operator, you can concatenate strings. In this case, we are concatenating the string "🥑" with the string "💻", resulting in "🥑💻".
With the + operator, you can concatenate strings. In this case, we are concatenating the string "🥑" with the string "💻", resulting in "🥑💻".
72. What's the output?
console.log(String.raw`Hello\nworld`);
console.log(String.raw`Hello\nworld`);
Anonymous Poll
38%
A: Hello world!
16%
B: Hello world
41%
C: Hello\nworld
6%
D: Hello\n world
DevScrolls
72. What's the output?
console.log(String.raw`Hello\nworld`);
console.log(String.raw`Hello\nworld`);
Answer: C
String.raw returns a string where the escapes (\n, \v, \t etc.) are ignored! Backslashes can be an issue since you could end up with something like:
const path =
Which would result in:
"C:DocumentsProjects able.html"
With String.raw, it would simply ignore the escape and print:
C:\Documents\Projects\table.html
In this case, the string is Hello\nworld, which gets logged.
String.raw returns a string where the escapes (\n, \v, \t etc.) are ignored! Backslashes can be an issue since you could end up with something like:
const path =
C:\Documents\Projects\table.htmlWhich would result in:
"C:DocumentsProjects able.html"
With String.raw, it would simply ignore the escape and print:
C:\Documents\Projects\table.html
In this case, the string is Hello\nworld, which gets logged.
73. What's the output?
async function getData() { return await Promise.resolve('I made it!'); } const data = getData(); console.log(data);
async function getData() { return await Promise.resolve('I made it!'); } const data = getData(); console.log(data);
Anonymous Poll
64%
A: "I made it!"
9%
B: Promise {<resolved>: "I made it!"}
9%
C: Promise {<pending>}
18%
D: undefined
DevScrolls
73. What's the output?
async function getData() { return await Promise.resolve('I made it!'); } const data = getData(); console.log(data);
async function getData() { return await Promise.resolve('I made it!'); } const data = getData(); console.log(data);
Answer: C
An async function always returns a promise. The await still has to wait for the promise to resolve: a pending promise gets returned when we call getData() in order to set data equal to it.
If we wanted to get access to the resolved value "I made it", we could have used the .then() method on data:
data.then(res => console.log(res))
This would've logged "I made it!"
An async function always returns a promise. The await still has to wait for the promise to resolve: a pending promise gets returned when we call getData() in order to set data equal to it.
If we wanted to get access to the resolved value "I made it", we could have used the .then() method on data:
data.then(res => console.log(res))
This would've logged "I made it!"
74. What's the output?
function addToList(item, list) {
return list.push(item);
}
const result = addToList('apple', ['banana']);
console.log(result);