DevScrolls
59 subscribers
2 photos
8 files
86 links
A thoughtful builder's journal — exploring modern frontend architecture, state management, design systems, and the craft of resilient software.

For more:

https://www.devscrolls.dev
Download Telegram
DevScrolls
85. What kind of information would get logged?

fetch('
https://www.website.com/api/user/1') .then(res => res.json()) .then(res => console.log(res));
Answer: C
The value of res in the second .then is equal to the returned value of the previous .then. You can keep chaining .thens like this, where the value is passed to the next handler.
86. Which option is a way to set hasName equal to true, provided you cannot pass true as an argument?

function getName(name) { const hasName = // }
Anonymous Poll
35%
A: !!name
26%
B: name
30%
C: new Boolean(name)
9%
D: name.length
DevScrolls
86. Which option is a way to set hasName equal to true, provided you cannot pass true as an argument?

function getName(name) { const hasName = // }
Answer: A
With !!name, we determine whether the value of name is truthy or falsy. If name is truthy, which we want to test for, !name returns false. !false (which is what !!name practically is) returns true.
By setting hasName equal to name, you set hasName equal to whatever value you passed to the getName function, not the boolean value true.
new Boolean(true) returns an object wrapper, not the boolean value itself.
name.length returns the length of the passed argument, not whether it's true.
87. What's the output?

console.log('I want pizza'[0]);
Anonymous Poll
17%
A: """
25%
B: "I"
17%
C: SyntaxError
42%
D: undefined
DevScrolls
87. What's the output?

console.log('I want pizza'[0]);
Answer: B
In order to get a character at a specific index of a string, you can use bracket notation. The first character in the string has index 0, and so on. In this case, we want to get the element with index 0, the character "I', which gets logged.
Note that this method is not supported in IE7 and below. In that case, use .charAt().
88. What's the output?

function sum(num1, num2 = num1) { console.log(num1 + num2); } sum(10);
Anonymous Poll
33%
A: NaN
28%
B: 20
28%
C: ReferenceError
11%
D: undefined
DevScrolls
88. What's the output?

function sum(num1, num2 = num1) { console.log(num1 + num2); } sum(10);
Answer: B
You can set a default parameter's value equal to another parameter of the function, as long as they've been defined before the default parameter. We pass the value 10 to the sum function. If the sum function only receives 1 argument, it means that the value for num2 is not passed, and the value of num1 is equal to the passed value 10 in this case. The default value of num2 is the value of num1, which is 10. num1 + num2 returns 20.
If you're trying to set a default parameter's value equal to a parameter which is defined after (to the right), the parameter's value hasn't been initialized yet, which will throw an error.
89. What's the output?
// module.js
export default () => 'Hello world'; export const name = 'Lydia'; // index.js import * as data from './module'; console.log(data);
Anonymous Poll
40%
A: { default: function default(), name: "Lydia" }
0%
B: { default: function default() }
60%
C: { default: "Hello world", name: "Lydia" }
0%
D: Global object of module.js
👍1
DevScrolls
89. What's the output?
// module.js
export default () => 'Hello world'; export const name = 'Lydia'; // index.js import * as data from './module'; console.log(data);
Answer: A
With the import * as name syntax, we import all exports from the module.js file into the index.js file as a new object called data is created. In the module.js file, there are two exports: the default export, and a named export. The default export is a function which returns the string "Hello World", and the named export is a variable called name which has the value of the string "Lydia".
The data object has a default property for the default export, other properties have the names of the named exports and their corresponding values.
90. What's the output?

class Person { constructor(name) { this.name = name; } } const member = new Person('John'); console.log(typeof member);
Anonymous Poll
28%
A: "class"
28%
B: "function"
28%
C: "object"
17%
D: "string"
DevScrolls
90. What's the output?

class Person { constructor(name) {
this.name = name; } } const member = new Person('John'); console.log(typeof member);
Answer: C
Classes are syntactical sugar for function constructors. The equivalent of the Person class as a function constructor would be:

function Person(name) {
this.name = name;
}


Calling a function constructor with new results in the creation of an instance of Person, typeof keyword returns "object" for an instance. typeof member returns "object".
91. What's the output?

let newList = [1, 2, 3].push(4); console.log(newList.push(5));
Anonymous Poll
50%
A: [1, 2, 3, 4, 5]
11%
B: [1, 2, 3, 5]
6%
C: [1, 2, 3, 4]
33%
D: Error
DevScrolls
91. What's the output?

let newList = [1, 2, 3].push(4); console.log(newList.push(5));
Answer: D

The .push method returns the new length of the array, not the array itself! By setting newList equal to [1, 2, 3].push(4), we set newList equal to the new length of the array: 4.
Then, we try to use the .push method on newList. Since newList is the numerical value 4, we cannot use the .push method: a TypeError is thrown
92. What's the output?

function giveLydiaPizza() {
return 'Here is pizza!';
}

const giveLydiaChocolate = () => "Here's chocolate... now go hit the gym already.";
console.log(giveLydiaPizza.prototype);
console.log(giveLydiaChocolate.prototype);
DevScrolls
Output?
Answer: D
Regular functions, such as the giveLydiaPizza function, have a prototype property, which is an object (prototype object) with a constructor property. Arrow functions however, such as the giveLydiaChocolate function, do not have this prototype property. undefined gets returned when trying to access the prototype property using giveLydiaChocolate.prototype.
93. What's the output?

const person = { name: 'Lydia', age: 21, };

for (const [x, y] of Object.entries(person)) {
console.log(x, y);
}