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

Home > Salesforce > Salesforce Developer > JavaScript-Developer-I

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

Question # 4

After user acceptance testing, the developer is asked to change the webpage background based on the user’s location. It works on the developer’s computer but not on the tester’s machine.

Which two actions will help determine accurate results?

A.

The tester should disable their browser cache.

B.

The developer should inspect their browser refresh settings.

C.

The tester should clear their browser cache.

D.

The developer should rework the code.

Full Access
Question # 5

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?

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);

Full Access
Question # 6

Refer to the following code (correcting the missing template literal backticks):

let codeName = ' Bond ' ;

let sampleText = `The name is ${codeName}, Jim ${codeName}`;

A developer is trying to determine if a certain substring is part of a string.

Which three code statements return true?

A.

sampleText.includes( ' Jim ' );

B.

sampleText.includes( ' The ' , 1);

C.

sampleText.includes( ' Jim ' , 4);

D.

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

E.

sampleText.substring( ' Jim ' );

Full Access
Question # 7

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?

A.

document.addEventListener( ' DOMContentLoaded ' , personalizeWebsiteContent);

B.

document.addEventListener( ' onDOMContentLoaded ' , personalizeWebsiteContent);

C.

window.addEventListener( ' load ' , personalizeWebsiteContent);

D.

window.addEventListener( ' onload ' , personalizeWebsiteContent);

Full Access
Question # 8

A developer executes:

document.cookie;

document.cookie = ' key=John Smith ' ;

What is the behavior?

A.

Cookies are read and the key value is set, the remaining cookies are unaffected.

B.

Cookies are read, but the key value is not set because the value is not URL encoded.

C.

Cookies are not read because line 01 should be document.cookies, but the key value is set and all cookies are wiped.

D.

Cookies are read and the key value is set, and all cookies are wiped.

Full Access
Question # 9

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?

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.)

Full Access
Question # 10

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

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.

Full Access
Question # 11

Code:

01 const sayHello = (name) = > {

02 console.log( ' Hello ' , name);

03 };

04

05 const world = () = > {

06 return ' World ' ;

07 };

08

09 sayHello(world);

This does not print " Hello World " .

What change is needed?

A.

Change line 2 to console.log( ' Hello ' , name());

B.

Change line 7 to }();

C.

Change line 9 to sayHello(world)();

D.

Change line 5 to function world() {

Full Access
Question # 12

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?

A.

super(size);

B.

ship.size = size;

C.

super.size = size;

D.

this.size = size;

Full Access
Question # 13

Original constructor function:

01 function Vehicle(name, price) {

02 this.name = name;

03 this.price = price;

04 }

05 Vehicle.prototype.priceInfo = function () {

06 return `Cost of the $(this.name) is $(this.price)$`;

07 }

08 var ford = new Vehicle( ' Ford Fiesta ' , ' 20,000 ' );

Which class definition is correct?

A.

class Vehicle {

constructor(name, price) {

this.name = name;

this.price = price;

}

priceInfo() {

return ' Cost of the ${this.name} is ${this.price}$ ' ;

}

}

B.

class Vehicle {

vehicle(name, price) {

this.name = name;

this.price = price;

}

priceInfo() {

return ' Cost of the ${this.name} is ${this.price}$ ' ;

}

}

C.

class Vehicle {

constructor() {

this.name = name;

this.price = price;

}

priceInfo() {

return `Cost of the ${this.name} is ${this.price}$`;

}

}

D.

class Vehicle {

constructor(name, price) {

this.name = name;

this.price = price;

}

priceInfo() {

return `Cost of the ${this.name} is ${this.price}$`;

}

}

Full Access
Question # 14

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.

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

Full Access
Question # 15

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

A.

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

B.

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

C.

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

D.

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

Full Access
Question # 16

A developer is creating a simple webpage with a button. When a user clicks this button for the first time, a message is displayed.

The developer wrote the JavaScript code below, but something is missing. The message gets displayed every time a user clicks the button, instead of just the first time.

01 function listen(event) {

02

03 alert( ' Hey! I am John Doe ' );

04

05 }

06 button.addEventListener( ' click ' , listen);

Which two code lines make this code work as required?

A.

On line 04, use event.stopPropagation();

B.

On line 02, use event.first to test if it is the first execution.

C.

On line 06, add an option called once to button.addEventListener().

D.

On line 04, use button.removeEventListener( ' click ' , listen);

Full Access
Question # 17

Refer to the following code block:

01 let array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11];

02 let output = 0;

03

04 for (let num of array) {

05 if (output > 10) {

06 break;

07 }

08 if (num % 2 == 0) {

09 continue;

10 }

11 output += num;

12 }

What is the value of output after the code executes?

A.

16

B.

25

C.

11

D.

36

Full Access
Question # 18

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;

}

}

A.

" msg is not defined "

B.

" newUserName "

C.

" Username available "

D.

undefined

Full Access
Question # 19

Refer to the code below:

let productSKU = ' 8675309 ' ;

A developer has a requirement to generate SKU numbers that are always 19 characters long, starting with ' sku ' , and padded with zeros.

Which statement assigns the value sku000000008675309?

A.

productSKU = productSKU.padEnd(16, ' 0 ' ).padStart( ' sku ' );

B.

productSKU = productSKU.padStart(16, ' 0 ' ).padStart(19, ' sku ' );

C.

productSKU = productSKU.padEnd(16, ' 0 ' ).padStart(19, ' sku ' );

D.

productSKU = productSKU.padStart(19, ' 0 ' ).padStart( ' sku ' );

Full Access
Question # 20

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?

A.

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

B.

server.start();

C.

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

D.

server();

Full Access
Question # 21

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?

A.

let res = fizzbuzz(3);

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

B.

let res = fizzbuzz(15);

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

C.

let res = fizzbuzz(NaN);

console.assert(isNaN(res));

D.

let res = fizzbuzz(Infinity);

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

Full Access
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?

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.

Full Access
Question # 23

Function to test:

01 const sum3 = (arr) = > {

02 if (!arr.length) return 0;

03 if (arr.length === 1) return arr[0];

04 if (arr.length === 2) return arr[0] + arr[1] ;

05 return arr[0] + arr[1] + arr[2];

06 };

Which two assert statements are valid tests for this function?

A.

console.assert(sum3([1, ' 2 ' ]) == 12);

B.

console.assert(sum3([ ' hello ' , 2, 3, 4]) === NaN);

C.

console.assert(sum3([-3, 2]) === -1);

D.

console.assert(sum3([0]) === 0);

Full Access
Question # 24

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?

A.

React

B.

Koa

C.

Vue

D.

Express

Full Access
Question # 25

Which statement accurately describes an aspect of promises?

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.

Full Access
Question # 26

Which actions can be done using the JavaScript browser console?

A.

Run code that’s not related to the page

B.

View and change the DOM of the page

C.

Display a report showing the performance of a page

D.

Change the DOM and the JavaScript code of the page

E.

View and change security cookies

Full Access
Question # 27

Refer to the HTML below:

< div id= " main " >

< ul >

< li > Leo < /li >

< li > Tony < /li >

< li > Tiger < /li >

< /ul >

< /div >

Which JavaScript statement results in changing " Leo " to " The Lion " ?

A.

document.querySelectorAll( ' #main #Leo ' ).innerHTML = ' The Lion ' ;

B.

document.querySelector( ' #main li:second-child ' ).innerHTML = ' The Lion ' ;

C.

document.querySelectorAll( ' #main li,Leo ' ).innerHTML = ' The Lion ' ;

D.

document.querySelector( ' #main li:nth-child(1) ' ).innerHTML = ' The Lion ' ;

Full Access
Question # 28

HTML:

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

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

A.

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

B.

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

C.

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

D.

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

Full Access
Question # 29

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?

A.

5-5

B.

5-10

C.

10-5

D.

10-10

Full Access
Question # 30

Refer to the code below:

01 let o = {

02 get js() {

03 let city1 = String( ' St. Louis ' );

04 let city2 = String( ' New York ' );

05

06 return {

07 firstCity: city1.toLowerCase(),

08 secondCity: city2.toLowerCase(),

09 }

10 }

11 }

What value can a developer expect when referencing o.js.secondCity?

A.

undefined

B.

An error

C.

' New York '

D.

' new york '

Full Access
Question # 31

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?

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.

Full Access
Question # 32

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?

A.

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

B.

(duplicate of A)

C.

Add .catch to the Promise chain

D.

Use finally handler for errors

Full Access
Question # 33

Which two console logs output NaN?

A.

console.log(10 / 0);

B.

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

C.

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

D.

console.log(10 / ' five ' );

Full Access
Question # 34

Given the following code:

01 let x = null;

02 console.log(typeof x);

What is the output of line 02?

A.

" object "

B.

" undefined "

C.

" x "

D.

" null "

Full Access
Question # 35

Corrected code:

let obj = {

foo: 1,

bar: 2

};

let output = [];

for (let something in obj) {

output.push(something);

}

console.log(output);

What is the output of line 11?

A.

[ " bar " , " foo " ]

B.

[1, 2]

C.

[ " foo " , " bar " ]

D.

[ " foo:1 " , " bar:2 " ]

Full Access
Question # 36

Refer to the code:

const pi = 3.1415926;

What is the data type of pi?

A.

Float

B.

Double

C.

Decimal

D.

Number

Full Access
Question # 37

Refer to the following code block (with corrected template literals using backticks):

01 class Animal {

02 constructor(name) {

03 this.name = name;

04 }

05

06 makeSound() {

07 console.log(`${this.name} is making a sound.`);

08 }

09 }

10

11 class Dog extends Animal {

12 constructor(name) {

13 super(name);

14 this.name = name;

15 }

16 makeSound() {

17 console.log(`${this.name} is barking.`);

18 }

19 }

20

21 let myDog = new Dog( ' Puppy ' );

22 myDog.makeSound();

What is the console output?

A.

> Uncaught ReferenceError

B.

> Undefined

C.

> Puppy is barking.

Full Access
Question # 38

Most accurate tests for:

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

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);

Full Access
Question # 39

A developer is setting up a Node.js server and is creating a script at the root of the source code, index.js, that will start the server when executed. The developer declares a variable that needs the folder location that the code executes from.

Which global variable can be used in the script?

A.

__filename

B.

window.location

C.

this.path

D.

__dirname

Full Access
Question # 40

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.

console.table(usersList);

B.

console.group(usersList);

C.

console.groupCollapsed(usersList);

D.

console.info(usersList);

Full Access
Question # 41

Why does second have access to variable a?

A.

Inner function ' s scope

B.

Outer function ' s scope

C.

Prototype Chain

D.

Hoisting

Full Access
Question # 42

let sampleText = " The quick brown fox jumps " ;

Which three expressions return true for a substring?

A.

sampleText.includes( ' fox ' );

B.

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

C.

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

D.

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

E.

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

Full Access
Question # 43

Which three actions can the code execute in the browser console?

A.

Run code that is not related to the page.

B.

View and change security cookies.

C.

Display a report showing the performance of a page.

D.

View, change, and debug the JavaScript code of the page.

E.

View and change the DOM of the page.

Full Access
Question # 44

Refer to the following code:

01 let obj = {

02 foo: 1,

03 bar: 2

04 }

05 let output = []

06

07 for (let something of obj) {

08 output.push(something);

09 }

10

11 console.log(output);

What is the value of output on line 11?

A.

An error will occur due to the incorrect usage of the for_of statement on line 07.

B.

[1, 2]

C.

[ " foo " , " bar " ]

D.

[ " foo:1 " , " bar:2 " ]

Full Access