81. What is the output?
function sayHi(name) { return `Hi there, ${name}`; } console.log(sayHi());
function sayHi(name) { return `Hi there, ${name}`; } console.log(sayHi());
Anonymous Poll
33%
A: Hi there,
38%
B: Hi there, undefined
13%
C: Hi there, null
17%
D: ReferenceError
83. What is the output?
const person = { name: 'Lydia', age: 21, }; let city = person.city; city = 'Amsterdam'; console.log(person);
const person = { name: 'Lydia', age: 21, }; let city = person.city; city = 'Amsterdam'; console.log(person);
Anonymous Poll
29%
A: { name: "Lydia", age: 21 }
33%
B: { name: "Lydia", age: 21, city: "Amsterdam" }
21%
C: { name: "Lydia", age: 21, city: undefined }
17%
D: "Amsterdam"
DevScrolls
81. What is the output?
function sayHi(name) { return `Hi there, ${name}`; } console.log(sayHi());
function sayHi(name) { return `Hi there, ${name}`; } console.log(sayHi());
Answer: B
By default, arguments have the value of undefined, unless a value has been passed to the function. In this case, we didn't pass a value for the name argument. name is equal to undefined which gets logged.
In ES6, we can overwrite this default undefined value with default parameters. For example:
function sayHi(name = "Lydia") { ... }
In this case, if we didn't pass a value or if we passed undefined, name would always be equal to the string Lydia
By default, arguments have the value of undefined, unless a value has been passed to the function. In this case, we didn't pass a value for the name argument. name is equal to undefined which gets logged.
In ES6, we can overwrite this default undefined value with default parameters. For example:
function sayHi(name = "Lydia") { ... }
In this case, if we didn't pass a value or if we passed undefined, name would always be equal to the string Lydia
DevScrolls
83. What is the output?
const person = { name: 'Lydia', age: 21, }; let city = person.city; city = 'Amsterdam'; console.log(person);
const person = { name: 'Lydia', age: 21, }; let city = person.city; city = 'Amsterdam'; console.log(person);
Answer: A
We set the variable city equal to the value of the property called city on the person object. There is no property on this object called city, so the variable city has the value of undefined.
Note that we are not referencing the person object itself! We simply set the variable city equal to the current value of the city property on the person object.
Then, we set city equal to the string "Amsterdam". This doesn't change the person object: there is no reference to that object.
When logging the person object, the unmodified object gets returned.
We set the variable city equal to the value of the property called city on the person object. There is no property on this object called city, so the variable city has the value of undefined.
Note that we are not referencing the person object itself! We simply set the variable city equal to the current value of the city property on the person object.
Then, we set city equal to the string "Amsterdam". This doesn't change the person object: there is no reference to that object.
When logging the person object, the unmodified object gets returned.
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));
fetch('https://www.website.com/api/user/1') .then(res => res.json()) .then(res => console.log(res));
Anonymous Poll
53%
A: The result of the fetch method.
26%
B: The result of the second invocation of the fetch method.
5%
C: The result of the callback in the previous .then()
16%
D: It would always be undefined.
https://thedailyfrontend.com/looping-statement-in-javascript/
Hey Folks 😃... I am about to write frontend articles every week from the basic concepts in JavaScript to Advance concepts with detailed explanations with real world scenarios for where to use and how to use them. Kindly give your support and happy learning 🤗
Hey Folks 😃... I am about to write frontend articles every week from the basic concepts in JavaScript to Advance concepts with detailed explanations with real world scenarios for where to use and how to use them. Kindly give your support and happy learning 🤗
The Daily Frontend
Looping Statement in JavaScript - The Daily Frontend
Looping statement in JavaScript allows us to run the same set of code again and again until some conditions are met. let's see in detail.
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));
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.
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 = // }
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 = // }
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.
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]);
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]);
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().
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);
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);
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.
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);
// 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);
// 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.
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);
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);
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:
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".
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));
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));
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
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
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);