Pre-Summer Sale Discount Flat 70% Offer - Ends in 0d 00h 00m 00s - Coupon code: 70diswrap

Salesforce JavaScript-Developer-I Dumps

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

Question 1

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 2

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 3

Code:

01 let array = [1, 2, 3, 4, 4, 5, 4, 4];

02 for (let i = 0; i < array.length; i++) {

03 if (array[i] === 4) {

04 array.splice(i, 1);

05 i--;

06 }

07 }

What is the value of array after execution?

Options:

A.

[1,2,3,4,5,4]

B.

[1,2,3,5]

C.

[1,2,3,4,5,4,4]

D.

[1,2,3,4,4,5,4]

Question 4

A developer removes the HTML class attribute from the checkout button, so now it is simply:

< button > Checkout < /button >

There is a test to verify the existence of the checkout button, however it looks for a button with class= " blue " . The test fails because no such button is found.

Which type of test category describes this test?

Options:

A.

True negative

B.

True positive

C.

False negative

D.

False positive

Question 5

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?

Options:

A.

03 try {

04 handleObjectValue(x);

05 } catch(error) {

06 handleError(error);

07 } then {

08 getNextValue();

09 }

B.

03 try {

04 handleObjectValue(x);

05 getNextValue();

06 } catch(error) {

07 handleError(error);

08 }

C.

03 try {

04 handleObjectValue(x);

05 } catch(error) {

06 handleError(error);

07 }

08 getNextValue();

D.

03 try {

04 handleObjectValue(x);

05 } catch(error) {

06 handleError(error);

07 } finally {

08 getNextValue();

09 }

Question 6

Refer to the code:

01 const exec = (item, delay) = >

02 new Promise(resolve = > setTimeout(() = > resolve(item), delay));

03

04 async function runParallel() {

05 const [result1, result2, result3] = await Promise.all(

06 [exec( ' x ' , ' 100 ' ), exec( ' y ' , ' 500 ' ), exec( ' z ' , ' 100 ' )]

07 );

08 return `parallel is done: ${result1}${result2}${result3}`;

09 }

Which two statements correctly execute runParallel()?

Options:

A.

async runParallel().then(data);

B.

runParallel().then(function(data){

return data;

});

C.

runParallel().done(function(data){

return data;

});

D.

runParallel().then(data);

Question 7

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 8

static delay = async delay = > {

return new Promise(resolve = > {

setTimeout(resolve, delay);

});

};

static asyncCall = async () = > {

await delay(1000);

console.log(1);

};

console.log(2);

asyncCall();

console.log(3);

Assume delay and asyncCall are in scope as functions.

What is logged to the console?

Options:

A.

1 2 3

B.

1 3 2

C.

2 1 3

D.

2 3 1

Question 9

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 10

Refer to the code snippet:

01 function getAvailableilityMessage(item) {

02 if (getAvailableility(item)) {

03 var msg = " Username available " ;

04 }

05 return msg;

06 }

What is the return value of msg when getAvailableilityMessage( " newUserName " ) is executed and getAvailableility( " newUserName " ) returns false?

Options:

A.

" newUserName "

B.

" msg is not defined "

C.

undefined

D.

" Username available "

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

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 13

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 14

01 function Animal(size, type) {

02 this.type = type || ' Animal ' ;

03 this.canTalk = false;

04 }

05

06 Animal.prototype.speak = function() {

07 if (this.canTalk) {

08 console.log( " It spoke! " );

09 }

10 };

11

12 let Pet = function(size, type, name, owner) {

13 Animal.call(this, size, type);

14 this.size = size;

15 this.name = name;

16 this.owner = owner;

17 }

18

19 Pet.prototype = Object.create(Animal.prototype);

20 let pet1 = new Pet();

Given the code above, which three properties are set for pet1?

Options:

A.

speak

B.

owner

C.

canTalk

D.

name

E.

type

Question 15

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 16

Which statement allows a developer to update the browser navigation history without a page refresh?

Options:

A.

window.customHistory.pushState(newStateObject, ' ' , null);

B.

window.history.createState(newStateObject, ' ' );

C.

window.history.pushState(newStateObject, ' ' , null);

D.

window.history.updateState(newStateObject, ' ' );

Question 17

Refer to the following array:

let arr = [1, 2, 3, 4, 5];

Which two lines of code result in a second array, arr2, created such that arr2 is a reference to arr?

Options:

A.

let arr2 = arr.slice(0, 5);

B.

let arr2 = Array.from(arr);

C.

let arr2 = arr;

D.

let arr2 = arr.sort();

Question 18

A Node.js server library uses events and callbacks. The developer wants to log any issues the server has at boot time.

Which code logs an error with an event?

Options:

A.

server.catch( ' error) = > {

console.log( ' ERROR ' , error);

});

B.

server.error( ' error) = > {

console.log( ' ERROR ' , error);

});

C.

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

console.log( ' ERROR ' , error);

});

D.

try {

server.start();

} catch(error) {

console.log( ' ERROR ' , error);

}

Question 19

Given:

const str = ' Salesforce ' ;

Which two statements result in ' Sales ' ?

Options:

A.

str.substring(0, 5);

B.

str.substring(1, 5);

C.

str.substr(0, 5);

D.

str.substr(1, 5);

Question 20

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 21

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?

Options:

A.

server.on( ' connect ' , (port) = > { console.log( ' Listening on ' , port); });

B.

server.start();

C.

server((port) = > { console.log( ' Listening on ' , port); });

D.

server();

Question 22

Console logging methods that allow string substitution:

Options:

A.

message

B.

log

C.

assert

D.

info

E.

error

Question 23

Given two expressions var1 and var2, what are two valid ways to return the concatenation of the two expressions and ensure it is data type string?

Options:

A.

String(var1).concat(var2)

B.

String.concat(var1 + var2)

C.

var1 + var2

D.

var1.toString() + var2.toString()

Question 24

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 25

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 26

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 27

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 28

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 29

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 30

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?

Options:

A.

node start

B.

npm start

C.

npm start server.js

D.

start server.js

Question 31

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 32

A developer creates a new web server that uses Node.js. It imports a server library that uses events and callbacks for handling server functionality. The server library is imported with require and is made available to the code by a variable named server. The developer wants to log any issues that the server has while booting up.

Which code logs an error at boot time with an event?

Options:

A.

server.error((error) = > {

console.log( ' ERROR ' , error);

});

B.

server.catch((error) = > {

console.log( ' ERROR ' , error);

});

C.

try {

server.start();

} catch(error) {

console.log( ' ERROR ' , error);

}

D.

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

console.log( ' ERROR ' , error);

});

Question 33

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 34

Refer to the code:

const pi = 3.1415926;

What is the data type of pi?

Options:

A.

Float

B.

Double

C.

Decimal

D.

Number

Question 35

Refer to the code below:

01 async function functionUnderTest(isOK) {

02 if (isOK) return ' OK ' ;

03 throw new Error( ' not OK ' );

04 }

Which assertion accurately tests the above code?

Options:

A.

console.assert(await functionUnderTest(true), ' OK ' )

B.

console.assert(await (functionUnderTest(true), ' not OK ' ))

C.

console.assert(functionUnderTest(true), ' OK ' )

D.

console.assert(await functionUnderTest(true), ' not OK ' )

Question 36

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 37

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 38

Refer to the code below:

const pi = 3.1415926;

What is the data type of pi?

Options:

A.

Number

B.

Float

C.

Double

D.

Decimal

Question 39

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 40

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 41

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 42

Refer to the code below:

01 let first = ' Who ' ;

02 let second = ' What ' ;

03 try {

04 try {

05 throw new Error( ' Sad trombone ' );

06 } catch (err) {

07 first = ' Why ' ;

08 throw err;

09 } finally {

10 second = ' When ' ;

11 }

12 } catch (err) {

13 second = ' Where ' ;

14 }

What are the values for first and second once the code executes?

Options:

A.

first is Who and second is Where.

B.

first is Why and second is Where.

C.

first is Who and second is When.

D.

first is Why and second is When.

Question 43

Original code:

01 let requestPromise = client.getRequest;

03 requestPromise().then((response) = > {

04 handleResponse(response);

05 });

The developer wants to gracefully handle errors from a Promise-based GET request.

Which code modification is correct?

Options:

A.

try/catch around requestPromise().then(...)

B.

(duplicate of A)

C.

Add .catch to the Promise chain

D.

Use finally handler for errors

Question 44

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 after the code executes?

Options:

A.

low

B.

10

C.

5

D.

undefined

Page: 1 / 15
Total 147 questions