Refer to the following object:
const dog = {
firstName: ' Beau ' ,
lastName: ' Boo ' ,
get fullName() {
return this.firstName + ' ' + this.lastName;
}
};
How can a developer access the fullName property for dog?
Refer to the code below:
01 let timedFunction = () = > {
02 console.log( ' Timer called. ' );
03 };
04
05 let timerId = setInterval(timedFunction, 1000);
Which statement allows a developer to cancel the scheduled timed function?
A developer wants to use a try...catch statement to catch any error that countSheep() may throw and pass it to a handleError() function.
What is the correct implementation of the try...catch?
At Universal Containers, every team has its own way of copying JavaScript objects. The code snippet shows an implementation from one team:
01 function Person() {
02 this.firstName = " John " ;
03 this.lastName = " Doe " ;
04 this.name = () = > {
05 console.log( ' Hello ${this.firstName} ${this.lastName} ' );
06 }
07 }
08
09 const john = new Person();
10 const dan = JSON.parse(JSON.stringify(john)); // (intended deep copy)
11 dan.firstName = ' Dan ' ;
12 dan.name();
(Original line 10 is logically intended to be JSON.parse(JSON.stringify(john)) to perform a JSON clone.)
What is the output of the code execution?
A class was written to represent items for purchase in an online store, and a second class representing items that are on sale at a discounted price. The constructor sets the name to the first value passed in. There is a new requirement for a developer to implement a description method that will return a brief description for Item and SaleItem.
01 let regItem = new Item( ' Scarf ' , 55);
02 let saleItem = new SaleItem( ' Shirt ' , 80, .1);
03 Item.prototype.description = function() { return ' This is a ' + this.name; }
04 console.log(regItem.description());
05 console.log(saleItem.description());
06
07 SaleItem.prototype.description = function() { return ' This is a discounted ' + this.name; }
What is the output when executing the code above?
Refer to the code below (assuming Promise.race is intended):
let cat3 = new Promise(resolve = >
setTimeout(resolve, 3000, " Cat 3 completes " )
);
Promise.race([cat1, cat2, cat3])
.then(value = > {
let result = `${value} the race.`;
})
.catch(err = > {
console.log( " Race is cancelled: " , err);
});
(Assuming cat1 and cat2 are similar to earlier examples: cat2 resolves fastest.)
What is the value of result when Promise.race executes?
Refer to the following code:
01 let obj = {
02 foo: 1,
03 bar: 2
04 }
05 let output = []
06
07 for (let something of obj) {
08 output.push(something);
09 }
10
11 console.log(output);
What is the value of output on line 11?
Refer to the code below:
01 x = 3.14;
02
03 function myFunction() {
04 ' use strict ' ;
05 y = x;
06 }
07
08 z = x;
09 myFunction();
Considering the implications of ' use strict ' on line 04, which three statements describe the execution of the code?
Correct implementation of try...catch for countsDeep():
Corrected code:
let obj = {
foo: 1,
bar: 2
};
let output = [];
for (let something in obj) {
output.push(something);
}
console.log(output);
What is the output of line 11?