Summer Sale Limited Time Flat 70% Discount offer - Ends in 0d 00h 00m 00s - Coupon code: 70spcl

Salesforce JavaScript-Developer-I Salesforce Certified JavaScript Developer (JS-Dev-101) Exam Practice Test

Salesforce Certified JavaScript Developer (JS-Dev-101) Questions and Answers

Question 1

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?

Options:

A.

super(size);

B.

ship.size = size;

C.

super.size = size;

D.

this.size = size;

Question 2

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?

Options:

A.

4 2 1 5 3

B.

4 2 1 5 3

C.

1 4 2 3 5

D.

4 5 1 2 3

Question 3

Which option is true about the strict mode in imported modules?

Options:

A.

Add the statement use non-strict; before any other statements in the module to enable notstrict mode.

B.

Imported modules are in strict mode whether you declare them as such or not.

C.

Add the statement use strict = false; before any other statements in the module to enable notstrict mode.

D.

A developer can only reference notStrict() functions from the imported module.

Question 4

HTML:

< p > The current status of an Order: < span id= " status " > In Progress < /span > < /p >

Which JavaScript statement changes ' In Progress ' to ' Completed ' ?

Options:

A.

document.getElementById( " .status " ).innerHTML = ' Completed ' ;

B.

document.getElementById( " #status " ).innerHTML = ' Completed ' ;

C.

document.getElementById( " status " ).innerHTML = ' Completed ' ;

D.

document.getElementById( " status " ).Value = ' Completed ' ;

Question 5

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?

Options:

A.

let res = fizzbuzz(true);

console.assert(res === ' ' );

B.

let res = fizzbuzz(3);

console.assert(res === ' ' );

C.

let res = fizzbuzz(5);

console.assert(res === ' fizz ' );

D.

let res = fizzbuzz(15);

console.assert(res === ' fizzbuzz ' );

Question 6

const str = ' Salesforce ' ;

Which two statements result in the word " Sales " ?

Options:

A.

str.substring(0, 5);

B.

str.substr(s, 5);

C.

str.substring(0, 5);

D.

str.substr(0, 5);

Question 7

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?

Options:

A.

25341

B.

12435

C.

12534

D.

21435

Question 8

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?

Options:

A.

False negative

B.

True positive

C.

True negative

D.

False positive

Question 9

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?

Options:

A.

Executes server-side JavaScript code to avoid learning a new language.

B.

Performs a static analysis on code before execution to look for runtime errors.

C.

Uses non-blocking functionality for performant request handling.

D.

Ensures stability with one major release every few years.

E.

Installs with its own package manager to install and manage third-party libraries.

Question 10

Refer to the code below:

01 let sayHello = () = > {

02 console.log( ' Hello, World! ' );

03 };

Which code executes sayHello once , two minutes from now?

Options:

A.

delay(sayHello, 120000);

B.

setTimeout(sayHello, 120000);

C.

setTimeout(sayHello(), 120000);

D.

setInterval(sayHello, 120000);

Question 11

Given the following code:

01 let x = null;

02 console.log(typeof x);

What is the output of line 02?

Options:

A.

" object "

B.

" undefined "

C.

" x "

D.

" null "

Question 12

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?

Options:

A.

The line 02 assertion fails.

B.

The line 05 assertion passes.

C.

The line 05 assertion fails.

D.

The line 02 assertion passes.

Question 13

Corrected code:

let a = " * " ;

let b = " ** " ;

// x = 3;

console.log(a);

What is displayed when the code executes?

Options:

A.

ReferenceError: a is not defined

B.

*

C.

undefined

D.

null

Question 14

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?

Options:

A.

The console logs only ' flag ' .

B.

An error is thrown.

C.

The console logs ' flag ' and then an error is thrown.

D.

The console logs ' flag ' and ' another flag ' .

Question 15

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?

Options:

A.

import * as lib from ' /path/universalContainerslib.js ' ;

lib.foo();

lib.bar();

B.

import * from ' /path/universalContainerslib.js ' ;

universalContainerslib.foo();

universalContainerslib.bar();

C.

import all from ' /path/universalContainerslib.js ' ;

universalContainerslib.foo();

universalContainerslib.bar();

D.

import {foo, bar} from ' /path/universalContainerslib.js ' ;

foo();

bar();

Question 16

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?

Options:

A.

console.table(usersList);

B.

console.group(usersList);

C.

console.groupCollapsed(usersList);

D.

console.info(usersList);

Question 17

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?

Options:

A.

userInformation.email

B.

userInformation.get( " email " )

C.

userInformation[ " email " ]

D.

userInformation[email]

Question 18

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?

Options:

A.

5-5

B.

5-10

C.

10-5

D.

10-10

Question 19

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?

Options:

A.

" John Developer "

B.

" John undefined "

C.

Error: myFather.job is not a function

D.

" undefined Developer "

Question 20

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?

Options:

A.

1.2.3

B.

1.1.4

C.

2.0.0

D.

1.2.0

Question 21

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?

Options:

A.

const server = require( ' secure-server ' );

B.

const tls = require( ' tls ' );

C.

const http = require( ' http ' );

D.

const https = require( ' https ' );

Question 22

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?

Options:

A.

The url variable has global scope and line 02 throws an error.

B.

The url variable has global scope and line 02 executes correctly.

C.

The url variable has local scope and line 02 executes correctly.

D.

The url variable has local scope and line 02 throws an error.

Question 23

Which statement accurately describes an aspect of promises?

Options:

A.

Arguments for the callback function passed to .then() are optional.

B.

.then() cannot be added after a catch.

C.

.then() manipulates and returns the original promise.

D.

In a .then() function, returning results is not necessary since callbacks will catch the result of a previous promise.

Question 24

Given the following code:

let x = ( ' 15 ' + 10) * 2;

What is the value of x?

Options:

A.

1520

B.

3020

C.

50

D.

35

Question 25

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?

Options:

A.

undefined

B.

5

C.

NaN

D.

10

Question 26

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?

Options:

A.

ws.connect(() = > {

console.log( ' Connected to client ' );

}).catch((error) = > {

console.log( ' ERROR ' , error);

});

B.

ws.on( ' connect ' , () = > {

console.log( ' Connected to client ' );

});

ws.on( ' error ' , (error) = > {

console.log( ' ERROR ' , error);

});

C.

ws.on( ' connect ' , () = > {

console.log( ' Connected to client ' );

});

ws.on( ' error ' , (error) = > {

console.log( ' ERROR ' , error);

});

D.

try {

ws.connect(() = > {

console.log( ' Connected to client ' );

});

} catch(error) {

console.log( ' ERROR ' , error);

}

Question 27

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?

Options:

A.

Better student Jackie got 70% on test.

B.

Uncaught ReferenceError

C.

Graduate Student Jane got 100% on test.

D.

Jackie got 70% on test.

Question 28

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?

Options:

A.

0122

B.

0123

C.

0112

D.

0012

Question 29

Given a value, which two options can a developer use to detect if the value is NaN?

Options:

A.

value === Number.NaN

B.

value == NaN

C.

isNaN(value)

D.

Object.is(value, NaN)

Question 30

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?

Options:

A.

Car 2 completed the race.

B.

Car 3 completed the race.

C.

Race is cancelled.

D.

Car 1 crashed in the race.

Question 31

Which two console logs output NaN?

Options:

A.

console.log(10 / 0);

B.

console.log(parseInt( ' two ' ));

C.

console.log(10 / Number( ' 5 ' ));

D.

console.log(10 / ' five ' );

Question 32

Value of:

true + 3 + ' 100 ' + null

Options:

A.

" 4100null "

B.

104

C.

" 4100 "

D.

" 2200null "

Question 33

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;

}

}

Options:

A.

" msg is not defined "

B.

" newUserName "

C.

" Username available "

D.

undefined

Question 34

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?

Options:

A.

leo.roar = () = > { console.log( ' They\ ' re pretty good! ' ); };

B.

Object.assign(leo, tony);

C.

Object.assign(leo, Tiger);

D.

leo.prototype.roar = () = > { console.log( ' They\ ' re pretty good! ' ); };

Question 35

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?

Options:

A.

04 const reader = new File();

08 if (file) reader.readAsDataURL(file);

B.

04 const reader = new FileReader();

08 if (file) reader.readAsDataURL(file);

C.

04 const reader = new FileReader();

08 if (file) URL.createObjectURL(file);

Question 36

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?

Options:

A.

11

B.

12

C.

10

D.

13

Question 37

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?

Options:

A.

2 2 2 2

B.

2 2 1 2

C.

2 2 1 1

D.

2 2 undefined undefined

Question 38

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?

Options:

A.

Add event.removeEventListener(); to window.onload event handler

B.

Add event.removeEventListener(); to printMessage function

C.

Add event.stopPropagation(); to printMessage function

D.

Add event.stopPropagation(); to window.onload event handler

Question 39

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()?

Options:

A.

import DatePrettyPrint() from ' /path/DatePrettyPrint.js ' ;

printDate();

B.

import DatePrettyPrint from ' /path/DatePrettyPrint.js ' ;

DatePrettyPrint.printDate();

C.

import printDate from ' /path/DatePrettyPrint.js ' ;

DatePrettyPrint.printDate();

D.

import printDate from ' /path/DatePrettyPrint.js ' ;

printDate();

Question 40

Which two implementations of utils.js support foo and bar?

Options:

A.

const foo = () = > { return ' foo ' ; };

const bar = () = > { return ' bar ' ; };

export { foo, bar };

B.

const foo = () = > { return ' foo ' ; };

const bar = () = > { return ' bar ' ; };

export default { foo, bar };

C.

import { foo, bar } from " ./helpers/utils.js " ;

export { foo, bar };

D.

export default class {

foo() { return ' foo ' ; }

bar() { return ' bar ' ; }

}

Question 41

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?

Options:

A.

{ type: ' update ' , recordId: ' 123abc ' }

B.

' update ' , { detail: { recordId: ' 123abc ' } }

C.

' update ' , ' 123abc '

D.

' update ' , { recordId: ' 123abc ' }

Question 42

Most accurate tests for:

const arr = Array(5).fill(0);

Options:

A.

console.assert(arr.length === 0);

B.

console.assert(arr[5] === 0 & & arr.length === 0);

C.

arr.forEach(e = > console.assert(e === 0));

D.

console.assert(arr.length === 5);

Question 43

Which two code snippets show working examples of a recursive function?

Options:

A.

const sumToTen = numVar = > {

if (numVar < 0)

return;

return sumToTen(numVar + 1);

};

B.

function factorial(numVar) {

if (numVar < 0) return;

if (numVar === 0) return 1;

return numVar - 1;

}

C.

const factorial = numVar = > {

if (numVar < 0) return;

if (numVar === 0) return 1;

return numVar * factorial(numVar - 1);

};

D.

let countingDown = function(startNumber) {

if (startNumber > 0) {

console.log(startNumber);

return countingDown(startNumber - 1);

} else {

return startNumber;

}

};

(Note: Option D is shown here with corrected syntax: lowercase return and matching parentheses.)

Question 44

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?

Options:

A.

Returns 0

B.

Throws an error

C.

Returns NaN

D.

Returns 5 ← (Text here appears to be a typo; correct value is 10, see explanation.)