Salesforce Certified JavaScript Developer - Multiple Choice - JS-Dev-101 Exam Practice Test
Question 1
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?
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: C
Explanation: Only visible for Actualtests4sure members. You can sign-up / login (it's free).
Question 2
Refer to the code below:
01 const server = require('server');
02
03 // Insert code here
A developer imports a library that creates a web server. The imported library uses events and callbacks to start the server.
Which code should be inserted at line 03 to set up an event and start the web server?
01 const server = require('server');
02
03 // Insert code here
A developer imports a library that creates a web server. The imported library uses events and callbacks to start the server.
Which code should be inserted at line 03 to set up an event and start the web server?
Correct Answer: A
Explanation: Only visible for Actualtests4sure members. You can sign-up / login (it's free).
Question 3
Correct implementation of try...catch for countsDeep():
Correct Answer: D
Explanation: Only visible for Actualtests4sure members. You can sign-up / login (it's free).
Question 4
A class was written to represent regular items and sale items. Code:
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; }
08 console.log(regItem.description());
09 console.log(saleItem.description());
What is the output?
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; }
08 console.log(regItem.description());
09 console.log(saleItem.description());
What is the output?
Correct Answer: A
Explanation: Only visible for Actualtests4sure members. You can sign-up / login (it's free).
Question 5
Refer to the code below:
class Student {
constructor(name) {
this._name = name;
}
displayGrade() {
console.log(`${this._name} got 70% on test.`);
}
}
class GraduateStudent extends Student {
constructor(name) {
super(name);
this._name = "Graduate Student " + name;
}
displayGrade() {
console.log(`${this._name} got 100% on test.`);
}
}
let student = new GraduateStudent("Jane");
student.displayGrade();
What is the console output?
class Student {
constructor(name) {
this._name = name;
}
displayGrade() {
console.log(`${this._name} got 70% on test.`);
}
}
class GraduateStudent extends Student {
constructor(name) {
super(name);
this._name = "Graduate Student " + name;
}
displayGrade() {
console.log(`${this._name} got 100% on test.`);
}
}
let student = new GraduateStudent("Jane");
student.displayGrade();
What is the console output?
Correct Answer: D
Explanation: Only visible for Actualtests4sure members. You can sign-up / login (it's free).
Question 6
Corrected code:
function Person() {
this.firstName = "John";
}
Person.prototype = {
job: x => "Developer"
};
const myFather = new Person();
const result = myFather.firstName + " " + myFather.job();
What is the value of result after line 10 executes?
function Person() {
this.firstName = "John";
}
Person.prototype = {
job: x => "Developer"
};
const myFather = new Person();
const result = myFather.firstName + " " + myFather.job();
What is the value of result after line 10 executes?
Correct Answer: C
Explanation: Only visible for Actualtests4sure members. You can sign-up / login (it's free).
Question 7
Given a value, which three options can a developer use to detect if the value is NaN?
Correct Answer: A,C,D
Question 8
A developer wants to create a simple image upload using the File API.
HTML:
<input type="file" onchange="previewFile()">
<img src="" height="200" alt="Image preview..." />
JavaScript:
01 function previewFile() {
02 const preview = document.querySelector('img');
03 const file = document.querySelector('input[type=file]').files[0];
04 // line 4 code
05 reader.addEventListener("load", () => {
06 preview.src = reader.result;
07 }, false);
08 // line 8 code
09 }
Which code in lines 04 and 08 allows the selected local image to be displayed?
HTML:
<input type="file" onchange="previewFile()">
<img src="" height="200" alt="Image preview..." />
JavaScript:
01 function previewFile() {
02 const preview = document.querySelector('img');
03 const file = document.querySelector('input[type=file]').files[0];
04 // line 4 code
05 reader.addEventListener("load", () => {
06 preview.src = reader.result;
07 }, false);
08 // line 8 code
09 }
Which code in lines 04 and 08 allows the selected local image to be displayed?
Correct Answer: C
Explanation: Only visible for Actualtests4sure members. You can sign-up / login (it's free).
Question 9
A developer is setting up a new Node.js server with a client library that is built using events and callbacks.
The library:
Will establish a web socket connection and handle receipt of messages to the server.
Will be imported with require, and made available with a variable called ws.
The developer also wants to add error logging if a connection fails.
Given this information, which code segment shows the correct way to set up a client with two events that listen at execution time?
The library:
Will establish a web socket connection and handle receipt of messages to the server.
Will be imported with require, and made available with a variable called ws.
The developer also wants to add error logging if a connection fails.
Given this information, which code segment shows the correct way to set up a client with two events that listen at execution time?
Correct Answer: A
Explanation: Only visible for Actualtests4sure members. You can sign-up / login (it's free).
Question 10
A developer has a fizzbuzz function that, when passed in a number, returns the following:
'fizz' if the number is divisible by 3.
'buzz' if the number is divisible by 5.
'fizzbuzz' if the number is divisible by both 3 and 5.
Empty string '' if the number is divisible by neither 3 nor 5.
Which two test cases properly test scenarios for the fizzbuzz function?
'fizz' if the number is divisible by 3.
'buzz' if the number is divisible by 5.
'fizzbuzz' if the number is divisible by both 3 and 5.
Empty string '' if the number is divisible by neither 3 nor 5.
Which two test cases properly test scenarios for the fizzbuzz function?
Correct Answer: B,D
Explanation: Only visible for Actualtests4sure members. You can sign-up / login (it's free).

