Summer Sale Limited Time 70% Discount Offer - Ends in 0d 00h 00m 00s - Coupon code: 70percent

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

A team at Universal Containers works on a big project and uses Yarn to deal with the project’s dependencies. A developer added a dependency to manipulate dates and pushed the updates to the remote repository. The rest of the team complains that the dependency does not get downloaded when they execute yarn.

What could be the reason for this?

Options:

A.

The developer missed the option --add when adding the dependency.

B.

The developer added the dependency as a dev dependency, and NODE_ENV is set to production.

C.

The developer added the dependency as a dev dependency, and YARN_ENV is set to production.

D.

The developer missed the option --save when adding the dependency.

Question 2

Refer to the following code:

< html lang= " en " >

< body >

< button class= " secondary " > Save draft < /button >

< button class= " primary " > Save and close < /button >

< /body >

< script >

function displaySaveMessage(event) {

console.log( ' Save message. ' );

}

function displaySuccessMessage(event) {

console.log( ' Success message. ' );

}

window.onload = function() {

document.querySelector( ' .secondary ' )

.addEventListener( ' click ' , displaySaveMessage, true);

document.querySelector( ' .primary ' )

.addEventListener( ' click ' , displaySuccessMessage, true);

}

< /script >

< /html >

Options:

A.

> Outer message

B.

> Outer message

Inner message

C.

> Inner message

D.

> Inner message

Outer message

Question 3

A developer imports:

import printPrice from ' /path/PricePrettyPrint.js ' ;

What must be true about printPrice for this import to work?

Options:

A.

printPrice must be a named export

B.

printPrice must be an all export

C.

printPrice must be the default export

D.

printPrice must be a multi export

Question 4

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 5

A developer is asked to fix some bugs reported by users. To do that, the developer adds a breakpoint for debugging.

01 function Car(maxSpeed, color) {

02 this.maxSpeed = maxSpeed;

03 this.color = color;

04 }

05 let carSpeed = document.getElementById( ' carSpeed ' );

06 debugger;

07 let fourWheels = new Car(carSpeed.value, ' red ' );

When the code execution stops at the breakpoint on line 06, which two types of information are available in the browser console?

Options:

A.

A variable displaying the number of instances created for the Car object

B.

The information stored in the window.localStorage property

C.

The values of the carSpeed and fourWheels variables

D.

The style, event listeners and other attributes applied to the carSpeed DOM element

Question 6

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 7

Given the code below:

01 function Person() {

02 this.firstName = ' John ' ;

03 }

04

05 Person.proto = {

06 job: x = > ' Developer '

07 });

08

09 const myFather = new Person();

10 const result = myFather.firstName + ' ' + myFather.job();

What is the value of result when line 10 executes?

Options:

A.

Error: myFather.job is not a function

B.

undefined Developer

C.

John Developer

D.

John undefined

Question 8

Given the JavaScript below:

function onLoad() {

console.log( " Page has loaded! " );

}

Where can the developer see the log statement after loading the page in the browser?

Options:

A.

On the browser JavaScript console

B.

On the terminal console running the web server

C.

In the browser performance tools log

D.

On the webpage console log

Question 9

Refer to the code below (corrected to use a template literal on line 08):

01 let car1 = new Promise((_, reject) = >

02 setTimeout(reject, 2000, " Car 1 crashed in " )

03 );

04 let car2 = new Promise(resolve = >

05 setTimeout(resolve, 1500, " Car 2 completed " )

06 );

07 let car3 = new Promise(resolve = >

08 setTimeout(resolve, 3000, " Car 3 completed " )

09 );

10

11 Promise.race([car1, car2, car3])

12 .then(value = > {

13 let result = `${value} the race.`;

14 })

15 .catch(err = > {

16 console.log( " Race is cancelled. " , err);

17 });

What is the value of result when Promise.race executes?

Options:

A.

Car 3 completed the race.

B.

Car 2 completed the race.

C.

Race is cancelled.

D.

Car 1 crashed in the race.

Question 10

Console logging methods that allow string substitution:

Options:

A.

message

B.

log

C.

assert

D.

info

E.

error

Question 11

A developer creates a simple webpage with an input field. When a user enters text and clicks the button, the actual value must be displayed in the console:

HTML:

< input type= " text " value= " Hello " name= " input " >

< button type= " button " > Display < /button >

JavaScript:

01 const button = document.querySelector( ' button ' );

02 button.addEventListener( ' click ' , () = > {

03 const input = document.querySelector( ' input ' );

04 console.log(input.getAttribute( ' value ' ));

05 });

When the user clicks the button, the output is always " Hello " .

What needs to be done to make this code work as expected?

Options:

A.

Replace line 02 with button.addCallback( " click " , function() {

B.

Replace line 03 with const input = document.getElementByIdName( ' input ' );

C.

Replace line 04 with console.log(input.value);

D.

Replace line 02 with button.addEventListener( " onclick " , function() {

Question 12

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?

Options:

A.

clearInterval(timerId);

B.

removeInterval(timerId);

C.

removeInterval(timedFunction);

D.

clearInterval(timedFunction);

Question 13

Why does second have access to variable a?

Options:

A.

Inner function ' s scope

B.

Outer function ' s scope

C.

Prototype Chain

D.

Hoisting

Question 14

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?

Options:

A.

Hello John Doe

B.

Hello Dan Doe

C.

TypeError: dan.name is not a function

D.

Hello Dan

Question 15

let sampleText = " The quick brown fox jumps " ;

Which three expressions return true for a substring?

Options:

A.

sampleText.includes( ' fox ' );

B.

sampleText.indexOf( ' quick ' ) > -1;

C.

sampleText.indexOf( ' fox ' ) !== -1;

D.

sampleText.include( ' fox ' ) !== -1;

E.

sampleText.indexOf( ' Quick ' ) !== -1;

Question 16

Which three browser specific APIs are available for developers to persist data between page loads?

Options:

A.

localStorage

B.

indexedDB

C.

cookies

D.

global variables

E.

IIFEs

Question 17

A developer wants to advocate for a mature, well-supported web framework/library instead of a new one (Minimalist.js).

Which two should be recommended?

Options:

A.

React

B.

Koa

C.

Vue

D.

Express

Question 18

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 19

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?

Options:

A.

dog.fullName

B.

dog.fullName()

C.

dog.get.fullName

D.

dog.function.fullName()

Question 20

A team at Universal Containers works on a big project and uses yarn to manage the project ' s dependencies.

A developer added a dependency to manipulate dates and pushed the updates to the remote repository. The rest of the team complains that the dependency does not get downloaded when they execute yarn .

What could be the reason for this?

Options:

A.

The developer added the dependency as a dev dependency, and YARN_ENV is set to production.

B.

The developer missed the option --save when adding the dependency.

C.

The developer added the dependency as a dev dependency, and NODE_ENV is set to production.

D.

The developer missed the option --add when adding the dependency.

Question 21

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 22

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 23

Given the code:

01 function GameConsole(name) {

02 this.name = name;

03 }

04

05 GameConsole.prototype.load = function(gamename) {

06 console.log( ' ${this.name} is loading a game: ${gamename}.... ' );

07 }

08

09 function Console16bit(name) {

10 GameConsole.call(this, name);

11 }

12

13 Console16bit.prototype = Object.create(GameConsole.prototype);

14

15 // insert code here

16 console.log( ' ${this.name} is loading a cartridge game: ${gamename}.... ' );

17 }

18

19 const console16bit = new Console16bit( ' SNEGeneziz ' );

20 console16bit.load( ' Super Monic 3x Force ' );

What should a developer insert at line 15?

Options:

A.

Console16bit = Object.create(GameConsole.prototype).load = function(gamename) {

B.

Console16bit.prototype.load(gamename) = function() {

C.

Console16bit.prototype.load(gamename) {

D.

Console16bit.prototype.load = function(gamename) {

Question 24

A developer has a module that contains multiple functions.

What kind of export should be leveraged so that multiple functions can be used?

Options:

A.

multi

B.

default

C.

all

D.

named

Question 25

Which statement accurately describes the behavior of the async/await keywords?

Options:

A.

The associated function sometimes returns a promise.

B.

The associated function can only be called via asynchronous methods.

C.

The associated class contains some asynchronous functions.

D.

The associated function is asynchronous, but acts like synchronous code.

Question 26

A developer at Universal Containers creates a new landing page based on HTML, CSS, and JavaScript.

To ensure that visitors have a good experience, a script named personalizeWebsiteContent needs to be executed to do some custom initialization when the webpage is fully loaded with HTML content and all related files.

Which statement should be used to call personalizeWebsiteContent based on the above business requirement?

Options:

A.

document.addEventListener( ' DOMContentLoaded ' , personalizeWebsiteContent);

B.

document.addEventListener( ' onDOMContentLoaded ' , personalizeWebsiteContent);

C.

window.addEventListener( ' load ' , personalizeWebsiteContent);

D.

window.addEventListener( ' onload ' , personalizeWebsiteContent);

Question 27

Refer to the code declarations below:

let str1 = ' Java ' ;

let str2 = ' Script ' ;

Which three expressions return the string JavaScript?

Options:

A.

`${str1}${str2}`

B.

str1.concat(str2);

C.

const({str1, str2});

D.

str1 + str2;

E.

str1.join(str2);

Question 28

Universal Containers (UC) just launched a new landing page, but users complain that the website is slow. A developer found some functions that might cause this problem. To verify this, the developer decides to execute everything and log the time each of these three suspicious functions consumes.

01 console.time( ' Performance ' );

02

03 maybeAHeavyFunction();

04

05 thisCouldTakeTooLong();

06

07 orMaybeThisOne();

08

09 console.endTime( ' Performance ' );

Which function can the developer use to obtain the time spent by every one of the three functions?

Options:

A.

console.timeLog()

B.

console.trace()

C.

console.timeStamp()

D.

console.getTime()

Question 29

Refer to the code:

01 console.log( ' Start ' );

02 Promise.resolve( ' Success ' ).then(function(value) {

03 console.log( ' Success ' );

04 });

05 console.log( ' End ' );

What is the output after the code executes successfully?

Options:

A.

Start

Success

End

B.

Start

End

Success

C.

End

Start

Success

D.

Success

Start

End

Question 30

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 31

What are two unique features of fat-arrow functions compared to normal function definitions?

Options:

A.

If the function has a single expression in the function body, the expression will be evaluated and implicitly returned.

B.

The function uses the this from the enclosing scope.

C.

The function receives an argument called parentThis, giving the enclosing lexical scope.

D.

The function generates its own this making it useful for separating scope.

Question 32

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 33

for (let number = 2; number < = 5; number += 1) {

// faster code statement here

}

Which statement meets the requirements to log an error when the Boolean statement evaluates to false?

Options:

A.

console.classy(number + 2 === 0);

B.

assert(number + 2 === 0);

C.

console.assert(number + 2 === 0);

D.

console.error(number + 2 === 0);

Question 34

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?

Options:

A.

This is a Scarf

Uncaught TypeError: saleItem.description is not a function

This is a Shirt

This is a discounted Shirt

B.

This is a Scarf

This is a Shirt

This is a Scarf

This is a discounted Shirt

C.

This is a Scarf

Uncaught TypeError: saleItem.description is not a function

This is a Scarf

This is a discounted Shirt

D.

This is a Scarf

This is a Shirt

This is a discounted Scarf

This is a discounted Shirt

Question 35

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 36

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 37

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 38

Given two expressions, exp1 and exp2, which two valid ways return the logical AND of the two expressions and ensure it is a Boolean?

Options:

A.

Boolean(exp1 & & exp2)

B.

Boolean(exp1) & & Boolean(exp2)

C.

exp1 & exp2

D.

Boolean(var1) & & Boolean(var2)

Question 39

Given the code below:

let numValue = 1982;

Which three code segments result in a correct conversion from number to string?

Options:

A.

let strValue = numValue.toText();

B.

let strValue = String(numValue);

C.

let strValue = ' ' + numValue;

D.

let strValue = numValue.toString();

E.

let strValue = (String)numValue;

Question 40

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?

Options:

A.

This is a Scarf

Uncaught TypeError: saleItem.description is not a function

This is a Scarf

This is a discounted Shirt

B.

This is a Scarf

This is a Shirt

This is a Scarf

This is a discounted Shirt

C.

This is a Scarf

This is a Shirt

This is a discounted Scarf

This is a discounted Shirt

D.

This is a Scarf

Uncaught TypeError: saleItem.description is not a function

This is a Shirt

This is a discounted Shirt

Question 41

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?

Options:

A.

Car 2 completed the race.

B.

Car 1 crashed on the race.

C.

Race is cancelled.

D.

Car 3 completed the race.

Question 42

A developer has two ways to write a function:

Option A:

01 function Monster() {

02 this.growl = () = > {

03 console.log( " Grr! " );

04 }

05 }

Option B:

01 function Monster() {};

02 Monster.prototype.growl = () = > {

03 console.log( " Grr! " );

04 }

After deciding on an option, the developer creates 1000 monster objects. How many growl methods are created with Option A and Option B?

Options:

A.

1000 growl methods are created regardless of which option is used.

B.

1 growl method is created regardless of which option is used.

C.

1000 growl methods are created for Option A. 1 growl method is created for Option B.

D.

1 growl method is created for Option A. 1000 growl methods are created for Option B.

Question 43

A developer publishes a new version of a package with bug fixes but no breaking changes. The old version number was 2.1.1.

What should the new package version number be based on semantic versioning?

Options:

A.

2.1.2

B.

2.2.0

C.

2.2.1

D.

3.1.1

Question 44

Given the code:

const copy = JSON.stringify([new String( ' false ' ), new Boolean(false), undefined]);

What is the value of copy?

Options:

A.

' [ " false " , false, null] '

B.

' [false, {}] '

C.

' [ " false " , false, undefined] '

D.

' [ " false " , {}] '