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
Output?
Answer: B
When you return a property, the value of the property is equal to the returned value, not the value set in the constructor function. We return the string "Maserati", so myCar.make is equal to "Maserati".
54. What's the output?

(() => { let x = (y = 10); })(); console.log(typeof x); console.log(typeof y);
Anonymous Poll
71%
A: "undefined", "number"
21%
B: "number", "number"
0%
C: "object", "number"
7%
D: "number", "undefined"
DevScrolls
54. What's the output?

(() => { let x = (y = 10); })(); console.log(typeof x); console.log(typeof y);
Answer: A
let x = (y = 10); is actually shorthand for:
y = 10; let x = y;
When we set y equal to 10, we actually add a property y to the global object (window in browser, global in Node). In a browser, window.y is now equal to 10.
Then, we declare a variable x with the value of y, which is 10. Variables declared with the let keyword are block scoped, they are only defined within the block they're declared in; the immediately invoked function expression (IIFE) in this case. When we use the typeof operator, the operand x is not defined: we are trying to access x outside of the block it's declared in. This means that x is not defined. Values who haven't been assigned a value or declared are of type "undefined". console.log(typeof x) returns "undefined".
However, we created a global variable y when setting y equal to 10. This value is accessible anywhere in our code. y is defined, and holds a value of type "number". console.log(typeof y) returns "number".
55. What's the output?

class Dog {
constructor(name) {
this.name = name;
}
}

Dog.prototype.bark = function() {
console.log(
Woof I am ${this.name});
};

const pet = new Dog('Mara');
pet.bark();
delete Dog.prototype.bark; pet.bark();
DevScrolls
Output?
Answer: A
We can delete properties from objects using the delete keyword, also on the prototype. By deleting a property on the prototype, it is not available anymore in the prototype chain. In this case, the bark function is not available anymore on the prototype after delete Dog.prototype.bark, yet we still try to access it.
When we try to invoke something that is not a function, a TypeError is thrown. In this case TypeError: pet.bark is not a function, since pet.bark is undefined.
56. What's the output?

const set = new Set([1, 1, 2, 3, 4]); console.log(set);
Anonymous Poll
38%
A: [1, 1, 2, 3, 4]
38%
B: [1, 2, 3, 4]
15%
C: {1, 1, 2, 3, 4}
8%
D: {1, 2, 3, 4}
DevScrolls
56. What's the output?

const set = new Set([1, 1, 2, 3, 4]); console.log(set);
Answer: D
The Set object is a collection of unique values: a value can only occur once in a set.
We passed the iterable [1, 1, 2, 3, 4] with a duplicate value 1. Since we cannot have two of the same values in a set, one of them is removed. This results in {1, 2, 3, 4}.
57. What's the output?

// counter.js

let counter = 10;
export default counter;



// index.js
import myCounter from './counter';

myCounter += 1; console.log(myCounter);
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.
58. What's the output?

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);
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.
59. What's the output?

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);
Answer: C
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);
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);
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 }.
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.