Salesforce Certified JavaScript Developer - Multiple Choice - JS-Dev-101 Exam Practice Test

Given the code below:
01 function Person(name, email) {
02 this.name = name;
03 this.email = email;
04 }
05
06 const john = new Person('John', '[email protected]');
07 const jane = new Person('Jane', '[email protected]');
08 const emily = new Person('Emily', '[email protected]');
09
10 let usersList = [john, jane, emily];
Which method can be used to provide a visual representation of the list of users and to allow sorting by the name or email attribute?
Correct Answer: C
Explanation: Only visible for TrainingDump members. You can sign-up / login (it's free).
A developer creates a class that represents a news story based on the requirements that a Story should have a body, author, and view count. The code is shown below:
01 class Story {
02 // Insert code here
03 this.body = body;
04 this.author = author;
05 this.viewCount = viewCount;
06 }
07 }
Which statement should be inserted in the placeholder on line 02 to allow for a variable to be set to a new instance of a Story with the three attributes correctly populated?
Correct Answer: D
Explanation: Only visible for TrainingDump members. You can sign-up / login (it's free).
A developer copied a JavaScript object:
01 function Person() {
02 this.firstName = "John";
03 this.lastName = "Doe";
04 this.name = () => `${this.firstName},${this.lastName}`;
05 }
06
07 const john = new Person();
08 const dan = Object.assign({}, john);
09 dan.firstName = 'Dan';
How does the developer access dan's firstName, lastName?
Correct Answer: D
Explanation: Only visible for TrainingDump members. You can sign-up / login (it's free).
Refer to the code below:
01 const objBook = {
02 title: 'JavaScript',
03 };
04 Object.preventExtensions(objBook);
05 const newObjBook = objBook;
06 newObjBook.author = 'Robert';
What are the values of objBook and newObjBook respectively?
Correct Answer: C
Explanation: Only visible for TrainingDump members. You can sign-up / login (it's free).
A developer initiates a server with the file server.js and adds dependencies in the source code's package.json that are required to run the server.
Which command should the developer run to start the server locally?
Correct Answer: D
Explanation: Only visible for TrainingDump members. You can sign-up / login (it's free).
Which option is true about the strict mode in imported modules?
Correct Answer: A
Explanation: Only visible for TrainingDump members. You can sign-up / login (it's free).
A developer wrote the following code:
01 let x = object.value;
02
03 try {
04 handleObjectValue(x);
05 } catch(error) {
06 handleError(error);
07 }
The developer has a getNextValue function to execute after handleObjectValue(), but does not want to execute getNextValue() if an error occurs. How can the developer change the code to ensure this behavior?
Correct Answer: B
Explanation: Only visible for TrainingDump members. You can sign-up / login (it's free).
Given a value, which two options can a developer use to detect if the value is NaN?
Correct Answer: C,D
Explanation: Only visible for TrainingDump members. You can sign-up / login (it's free).
Refer to the code below:
01 let total = 10;
02 const interval = setInterval(() => {
03 total++;
04 clearInterval(interval);
05 total++;
06 }, 0);
07 total++;
08 console.log(total);
Considering that JavaScript is single-threaded, what is the output of line 08 after the code executes?
Correct Answer: A
Explanation: Only visible for TrainingDump members. You can sign-up / login (it's free).
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?
Correct Answer: B
Explanation: Only visible for TrainingDump members. You can sign-up / login (it's free).
0
0
0
0