DevScrolls
Output?
Answer: C
An imported module is read-only: you cannot modify the imported module. Only the module that exports them can change its value.
When we try to increment the value of myCounter, it throws an error: myCounter is read-only and cannot be modified.
An imported module is read-only: you cannot modify the imported module. Only the module that exports them can change its value.
When we try to increment the value of myCounter, it throws an error: myCounter is read-only and cannot be modified.
58. What's the output?
const name = 'Lydia'; age = 21; console.log(delete name); console.log(delete age);
const name = 'Lydia'; age = 21; console.log(delete name); console.log(delete age);
Anonymous Poll
40%
A: false, true
5%
B: "Lydia", 21
10%
C: true, true
45%
D: undefined, undefined
DevScrolls
58. What's the output?
const name = 'Lydia'; age = 21; console.log(delete name); console.log(delete age);
const name = 'Lydia'; age = 21; console.log(delete name); console.log(delete age);
Answer: A
The delete operator returns a boolean value: true on a successful deletion, else it'll return false. However, variables declared with the var, const or let keyword cannot be deleted using the delete operator.
The name variable was declared with a const keyword, so its deletion is not successful: false is returned. When we set age equal to 21, we actually added a property called age to the global object. You can successfully delete properties from objects this way, also the global object, so delete age returns true.
The delete operator returns a boolean value: true on a successful deletion, else it'll return false. However, variables declared with the var, const or let keyword cannot be deleted using the delete operator.
The name variable was declared with a const keyword, so its deletion is not successful: false is returned. When we set age equal to 21, we actually added a property called age to the global object. You can successfully delete properties from objects this way, also the global object, so delete age returns true.
59. What's the output?
const numbers = [1, 2, 3, 4, 5]; const [y] = numbers; console.log(y);
const numbers = [1, 2, 3, 4, 5]; const [y] = numbers; console.log(y);
Anonymous Poll
50%
A: [[1, 2, 3, 4, 5]]
29%
B: [1, 2, 3, 4, 5]
21%
C: 1
0%
D: [1]
DevScrolls
59. What's the output?
const numbers = [1, 2, 3, 4, 5]; const [y] = numbers; console.log(y);
const numbers = [1, 2, 3, 4, 5]; const [y] = numbers; console.log(y);
Answer: C
We can unpack values from arrays or properties from objects through destructuring. For example:

The value of a is now 1, and the value of b is now 2. What we actually did in the question, is:

This means that the value of y is equal to the first value in the array, which is the number 1. When we log y, 1 is returned.
We can unpack values from arrays or properties from objects through destructuring. For example:
[a, b] = [1, 2];
The value of a is now 1, and the value of b is now 2. What we actually did in the question, is:
[y] = [1, 2, 3, 4, 5];
This means that the value of y is equal to the first value in the array, which is the number 1. When we log y, 1 is returned.
60. What's the output?
const user = { name: 'Lydia', age: 21 }; const admin = { admin: true, ...user }; console.log(admin);
const user = { name: 'Lydia', age: 21 }; const admin = { admin: true, ...user }; console.log(admin);
Anonymous Poll
37%
A: { admin: true, user: { name: "Lydia", age: 21 } }
48%
B: { admin: true, name: "Lydia", age: 21 }
11%
C: { admin: true, user: ["Lydia", 21] }
4%
D: { admin: true }
DevScrolls
60. What's the output?
const user = { name: 'Lydia', age: 21 }; const admin = { admin: true, ...user }; console.log(admin);
const user = { name: 'Lydia', age: 21 }; const admin = { admin: true, ...user }; console.log(admin);
Answer: B
It's possible to combine objects using the spread operator .... It lets you create copies of the key/value pairs of one object, and add them to another object. In this case, we create copies of the user object, and add them to the admin object. The admin object now contains the copied key/value pairs, which results in { admin: true, name: "Lydia", age: 21 }.
It's possible to combine objects using the spread operator .... It lets you create copies of the key/value pairs of one object, and add them to another object. In this case, we create copies of the user object, and add them to the admin object. The admin object now contains the copied key/value pairs, which results in { admin: true, name: "Lydia", age: 21 }.
61. What's the output?
const person = { name: 'Lydia' }; Object.defineProperty(person, 'age', { value: 21 });
console.log(person);
console.log(Object.keys(person));
DevScrolls
61. What's the output? const person = { name: 'Lydia' }; Object.defineProperty(person, 'age', { value: 21 }); console.log(person); console.log(Object.keys(person));
DevScrolls
Output?
Answer: B
With the defineProperty method, we can add new properties to an object, or modify existing ones. When we add a property to an object using the defineProperty method, they are by default not enumerable. The Object.keys method returns all enumerable property names from an object, in this case only "name".
Properties added using the defineProperty method are immutable by default. You can override this behavior using the writable, configurable and enumerable properties. This way, the defineProperty method gives you a lot more control over the properties you're adding to an object.
With the defineProperty method, we can add new properties to an object, or modify existing ones. When we add a property to an object using the defineProperty method, they are by default not enumerable. The Object.keys method returns all enumerable property names from an object, in this case only "name".
Properties added using the defineProperty method are immutable by default. You can override this behavior using the writable, configurable and enumerable properties. This way, the defineProperty method gives you a lot more control over the properties you're adding to an object.
62. What's the output?
const settings = { username: 'lydiahallie', level: 19, health: 90, };
const data = JSON.stringify(settings, ['level', 'health']);
console.log(data);
DevScrolls
62. What's the output? const settings = { username: 'lydiahallie', level: 19, health: 90, }; const data = JSON.stringify(settings, ['level', 'health']); console.log(data);
DevScrolls
Output?
Answer: A
The second argument of JSON.stringify is the replacer. The replacer can either be a function or an array, and lets you control what and how the values should be stringified.
If the replacer is an array, only the property names included in the array will be added to the JSON string. In this case, only the properties with the names "level" and "health" are included, "username" is excluded. data is now equal to "{"level":19, "health":90}".
If the replacer is a function, this function gets called on every property in the object you're stringifying. The value returned from this function will be the value of the property when it's added to the JSON string. If the value is undefined, this property is excluded from the JSON string.
The second argument of JSON.stringify is the replacer. The replacer can either be a function or an array, and lets you control what and how the values should be stringified.
If the replacer is an array, only the property names included in the array will be added to the JSON string. In this case, only the properties with the names "level" and "health" are included, "username" is excluded. data is now equal to "{"level":19, "health":90}".
If the replacer is a function, this function gets called on every property in the object you're stringifying. The value returned from this function will be the value of the property when it's added to the JSON string. If the value is undefined, this property is excluded from the JSON string.
63. What's the output?
let num = 10;
const increaseNumber = () => num++;
const increasePassedNumber = number => number++;
const num1 = increaseNumber();
const num2 = increasePassedNumber(num1);
console.log(num1); console.log(num2);
DevScrolls
Output?
Answer: A
The unary operator ++ first returns the value of the operand, then increments the value of the operand. The value of num1 is 10, since the increaseNumber function first returns the value of num, which is 10, and only increments the value of num afterwards.
num2 is 10, since we passed num1 to the increasePassedNumber. number is equal to 10(the value of num1. Again, the unary operator ++ first returns the value of the operand, then increments the value of the operand. The value of number is 10, so num2 is equal to 10.
The unary operator ++ first returns the value of the operand, then increments the value of the operand. The value of num1 is 10, since the increaseNumber function first returns the value of num, which is 10, and only increments the value of num afterwards.
num2 is 10, since we passed num1 to the increasePassedNumber. number is equal to 10(the value of num1. Again, the unary operator ++ first returns the value of the operand, then increments the value of the operand. The value of number is 10, so num2 is equal to 10.
64. What's the output?
const value = { number: 10 };
const multiply = (x = { ...value }) => {
console.log((x.number *= 2));
};
multiply();
multiply(); multiply(value); multiply(value);
DevScrolls
64. What's the output? const value = { number: 10 }; const multiply = (x = { ...value }) => { console.log((x.number *= 2)); }; multiply(); multiply(); multiply(value); multiply(value);
Output?
Anonymous Poll
33%
A: 20, 40, 80, 160
0%
B: 20, 40, 20, 40
50%
C: 20, 20, 20, 40
17%
D: NaN, NaN, 20, 40