Salesforce JavaScript-Developer-I Salesforce Certified JavaScript Developer (JS-Dev-101) Exam Practice Test
Total 147 questions
Salesforce Certified JavaScript Developer (JS-Dev-101) Questions and Answers
Refer to the following code:
01 class Ship {
02 constructor(size) {
03 this.size = size;
04 }
05 }
06
07 class FishingBoat extends Ship {
08 constructor(size, capacity){
09 //Missing code
10 this.capacity = capacity;
11 }
12 displayCapacity() {
13 console.log( ' The boat has a capacity of ${this.capacity} people. ' );
14 }
15 }
16
17 let myBoat = new FishingBoat( ' medium ' , 10);
18 myBoat.displayCapacity();
Which statement should be added to line 09 for the code to display
The boat has a capacity of 10 people?
Given the code below:
01 const delay = async delay = > {
02 return new Promise((resolve, reject) = > {
03 console.log(1);
04 setTimeout(resolve, delay);
05 });
06 };
07
08 const callDelay = async () = > {
09 console.log(2);
10 const yup = await delay(1000);
11 console.log(3);
12 };
13
14 console.log(4);
15 callDelay();
16 console.log(5);
What is logged to the console?
Which option is true about the strict mode in imported modules?
HTML:
< p > The current status of an Order: < span id= " status " > In Progress < /span > < /p >
Which JavaScript statement changes ' In Progress ' to ' Completed ' ?
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?
const str = ' Salesforce ' ;
Which two statements result in the word " Sales " ?
Given the code below:
01 setTimeout(() = > {
02 console.log(1);
03 }, 1100);
04 console.log(2);
05 new Promise((resolve, reject) = > {
06 setTimeout(() = > {
07 reject(console.log(3));
08 }, 1000);
09 }).catch(() = > {
10 console.log(4);
11 });
12 console.log(5);
What is logged to the console?
A test searches for:
< button class= " blue " > Checkout < /button >
But the actual HTML is:
< button > Checkout < /button >
The test fails because it expects a class that no longer exists.
What type of test outcome is this?
A developer is trying to convince management that their team will benefit from using Node.js for a backend server that they are going to create. The server will be a web server that handles API requests from a website that the team has already built using HTML, CSS, and JavaScript.
Which three benefits of Node.js can the developer use to persuade their manager?
Refer to the code below:
01 let sayHello = () = > {
02 console.log( ' Hello, World! ' );
03 };
Which code executes sayHello once , two minutes from now?
Given the following code:
01 let x = null;
02 console.log(typeof x);
What is the output of line 02?
A developer wrote the following code to test a sum3 function that takes in an array of numbers and returns the sum of the first three numbers in the array. The test passes:
01 let res = sum3([1, 2, 3]);
02 console.assert(res === 6);
03
04 res = sum3([1, 2, 3, 4]);
05 console.assert(res === 6);
A different developer made changes to the behavior of sum3 to instead sum all of the numbers present in the array.
Which two results occur when running the test on the updated sum3 function?
Corrected code:
let a = " * " ;
let b = " ** " ;
// x = 3;
console.log(a);
What is displayed when the code executes?
Refer to the code below:
flag();
function flag() {
console.log( ' flag ' );
}
const anotherFlag = () = > {
console.log( ' another flag ' );
}
anotherFlag();
What is result of the code block?
A developer wants to use a module named universalContainerslib and then call functions from it. How should a developer import every function from the module and then call the functions foo and bar?
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 ' , ' john@email.com ' );
07 const jane = new Person( ' Jane ' , ' jane@email.com ' );
08 const emily = new Person( ' Emily ' , ' emily@email.com ' );
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?
A developer uses a parsed JSON string to work with user information as in the block below:
01 const userInformation = {
02 " id " : " user-01 " ,
03 " email " : " user01@universalcontainers.demo " ,
04 " age " : 25
05 };
Which two options access the email attribute in the object?
Refer to the code below:
01 function changeValue(param) {
02 param = 5;
03 }
04 let a = 10;
05 let b = a;
06
07 changeValue(b);
08 const result = a + ' - ' + b;
What is the value of result when the code executes?
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?
A developer publishes a new version of a package with new features that do not break backward compatibility. The previous version number was 1.1.3.
Following semantic versioning formats, what should the new package version number be?
A developer wants to set up a secure web server with Node.js. The developer creates a directory locally called app-server, and the first file is app-server/index.js.
Without using any third-party libraries, what should the developer add to index.js to create the secure web server?
Given the code below:
01 setCurrentUrl();
02 console.log( " The current URL is: " + url);
03
04 function setCurrentUrl() {
05 url = window.location.href;
06 }
What happens when the code executes?
Which statement accurately describes an aspect of promises?
Given the following code:
let x = ( ' 15 ' + 10) * 2;
What is the value of x?
01 function changeValue(obj) {
02 obj.value = obj.value / 2;
03 }
04 const objA = { value: 10 };
05 const objB = objA;
06
07 changeValue(objB);
08 const result = objA.value;
What is the value of result?
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?
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?
Given the following code:
01 counter = 0;
02 const logCounter = () = > {
03 console.log(counter);
04 };
05 logCounter();
06 setTimeout(logCounter, 2100);
07 setInterval(() = > {
08 counter++;
09 logCounter();
10 }, 1000);
What will be the first four numbers logged?
Given a value, which two options can a developer use to detect if the value is NaN?
Refer to the code:
01 let car1 = new Promise((_, reject) = >
02 setTimeout(reject, 2000, " Car 1 crashed in " ));
03 let car2 = new Promise(resolve = >
04 setTimeout(resolve, 1500, " Car 2 completed " ));
05 let car3 = new Promise(resolve = >
06 setTimeout(resolve, 3000, " Car 3 completed " ));
07
08 Promise.race([car1, car2, car3])
09 .then(value = > {
10 let result = ' $(value) the race. ' ;
11 })
12 .catch(err = > {
13 console.log( " Race is cancelled. " , err);
14 });
What is the value of result when Promise.race executes?
Which two console logs output NaN?
Value of:
true + 3 + ' 100 ' + null
A developer writes the code below to return a message to a user attempting to register a new username. If the username is available, a variable named msg is declared and assigned a value on line 03.
function getAvailabilityMessage(item) {
if (getAvailability(item)) {
var msg = " Username available " ;
return msg;
}
}
JavaScript:
01 function Tiger() {
02 this.type = ' Cat ' ;
03 this.size = ' large ' ;
04 }
05
06 let tony = new Tiger();
07 tony.roar = () = > {
08 console.log( ' They\ ' re great! ' );
09 };
10
11 function Lion() {
12 this.type = ' Cat ' ;
13 this.size = ' large ' ;
14 }
15
16 let leo = new Lion();
17 // Insert code here
18 leo.roar();
Which two statements could be inserted at line 17 to enable line 18?
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?
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?
Refer to the code below:
01 function myFunction(reassign) {
02 let x = 1;
03 var y = 1;
04
05 if (reassign) {
06 let x = 2;
07 var y = 2;
08 console.log(x);
09 console.log(y);
10 }
11
12 console.log(x);
13 console.log(y);
14 }
What is displayed when myFunction(true) is called?
Refer to the code below:
< html >
< body >
< div id= " logo " > Hello Logo! < /div >
< button id= " test " > Click me < /button >
< /body >
< script >
function printMessage(event) {
console.log( ' This is a test message ' );
}
let el = document.getElementById( ' test ' );
el.addEventListener( " click " , printMessage, false);
< /script >
< /html >
Which action should be done?
A developer wants to use a module called DatePrettyPrint.
This module exports one default function called printDate().
How can the developer import and use printDate()?
Which two implementations of utils.js support foo and bar?
Refer to the code:
01 const event = new CustomEvent(
02 // Missing code
03 );
04 obj.dispatchEvent(event);
A developer needs to dispatch a custom event called update to send information about recordId.
Which two options can be inserted at line 02?
Most accurate tests for:
const arr = Array(5).fill(0);
Which two code snippets show working examples of a recursive function?
Refer to the code below:
01 const myFunction = arr = > {
02 return arr.reduce((result, current) = > {
03 return result + current;
04 }, 10);
05 }
What is the output of this function when called with an empty array?
Total 147 questions