This is the 12th day of my participation in Gwen Challenge
136. Which of the following would have side effects on the object Person?
const person = { name: "Lydia Hallie" };
Object.seal(person);
Copy the code
A: [A] Add A new attribute. [C] delete the original attribute. [D] assign all attributes of an enumerable Object from the source Object to the target Object and return the target Object. So only item A has side effects on the Person object.
137. Which of the following has a side effect on the object Person?
const person = {
name: "Lydia Hallie".address: {
street: "100 Main St"}};Object.freeze(person);
Copy the code
A) Freeze B) Freeze C) Freeze D) freeze
138. Output what?
const add = x= > x + x;
function myFunc(num = 2, value = add(num)) {
console.log(num, value);
}
myFunc();
myFunc(3);
Copy the code
A) The default parameter is passed by default.
139. Output what?
class Counter {
#number = 10
increment() {
this.#number++
}
getNum() {
return this.#number
}
}
const counter = new Counter()
counter.increment()
console.log(counter.#number)
Copy the code
D) You can access the private attributes of a class by using an instance method.
140. Which one to choose?
const teams = [
{ name: "Team 1".members: ["Paul"."Lisa"] {},name: "Team 2".members: ["Laura"."Tim"]}];function* getMembers(members) {
for (let i = 0; i < members.length; i++) {
yieldmembers[i]; }}function* getTeams(teams) {
for (let i = 0; i < teams.length; i++) {
// ✨ SOMETHING IS MISSING HERE ✨}}const obj = getTeams(teams);
obj.next(); // { value: "Paul", done: false }
obj.next(); // { value: "Lisa", done: false }
Copy the code
A) delegate a function to a generator function B) delegate a function to a generator function C) delegate a function to a generator function D) delegate a function to an iterable
141. Output what?
const person = {
name: "Lydia Hallie".hobbies: ["coding"]};function addHobby(hobby, hobbies = person.hobbies) {
hobbies.push(hobby);
return hobbies;
}
addHobby("running"[]); addHobby("dancing");
addHobby("baking", person.hobbies);
console.log(person.hobbies);
Copy the code
(C) Passing a reference to a person object (D) passing a reference to hobbies (D) passing a reference to a person object (D) passing a reference to hobbies (D) passing a reference to a person object
142. Output what?
class Bird {
constructor() {
console.log("I 'm a bird. 🦢"); }}class Flamingo extends Bird {
constructor() {
console.log("I'm pink. 🌸");
super();
}
}
const pet = new Flamingo();
Copy the code
The constructor of the subclass is called first, and the constructor of the parent class is called second, so it prints B.
143. Which option causes an error?
const emojis = ["🎄"."🎅 🏼"."🎁"."⭐"];
/ * 1 * / emojis.push("🦌");
/ * 2 * / emojis.splice(0.2);
/ * * / 3 emojis = [...emojis, "🥂"];
/ * * / 4 emojis.length = 0;
Copy the code
D, the length attribute can be changed, so the fourth error is not allowed. The third error is to change the address of emojis, which is not allowed because this is const keyword.
144. What do we need to add to the person object so that executing […person] gets output of the form [“Lydia Hallie”, 21]?
const person = {
name: "Lydia Hallie".age: 21
}
[...person] // ["Lydia Hallie", 21]
Copy the code
C) Add iterators to define iteration rules. Objects are not iterable by default. When adding rules, generator objects must yield* object.values.
145. Output what?
let count = 0;
const nums = [0.1.2.3];
nums.forEach(num= > {
if (num) count += 1
})
console.log(count)
Copy the code
C) count is not added three times when num is 0.
Title source
Github.com/lydiahallie…