Summer Sale - Special 70% Discount Offer - Ends in 0d 00h 00m 00s - Coupon code: 70dumps

JavaScript-Developer-I Questions and Answers

Question # 6

A developer implements a function that adds a few values.

function sum(num1, num2, num3) {

if (num3 === undefined) {

num3 = 0;

}

return num1 + num2 + num3;

}

Which three options can the developer invoke for this function to get a return value of 10?

A.

sum(5)(5);

B.

sum()(10);

C.

sum(5, 5, 0);

D.

sum(10, 0);

E.

sum(5, 2, 3);

Full Access
Question # 7

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?

A.

" newUserName "

B.

" msg is not defined "

C.

undefined

D.

" Username available "

Full Access
Question # 8

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 # 9

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?

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

}

Full Access
Question # 10

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?

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

Full Access
Question # 11

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.

1.2.3

B.

1.1.4

C.

2.0.0

D.

1.2.0

Full Access
Question # 12

Refer to the code snippet:

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

A.

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

B.

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

C.

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

D.

[1, 2, 3, 5]

Full Access
Question # 13

A developer is required to write a function that calculates the sum of elements in an array but is getting undefined every time the code is executed. The developer needs to find what is missing in the code below.

01 const sumFunction = arr = > {

02 return arr.reduce((result, current) = > {

03 //

04 result += current;

05 //

06 }, 10);

07 };

Which line replacement makes the code work as expected?

A.

03 if(arr.length == 0) { return 0; }

B.

04 result = result + current;

C.

02 arr.map((result, current) = > {

D.

05 return result;

Full Access
Question # 14

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

A.

localStorage

B.

indexedDB

C.

cookies

D.

global variables

E.

IIFEs

Full Access
Question # 15

function myFunction() {

a = a + b;

var b = 1;

}

myFunction();

console.log(a);

console.log(b);

Which statement is correct?

A.

Line 02 throws a reference error, therefore line 03 is never executed.

B.

Both line 02 and 03 are executed, but the values printed are undefined.

C.

Both line 02 and 03 are executed, and the variables are hoisted.

D.

Line 08 outputs the variable, but line 09 throws an error.

Full Access
Question # 16

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 # 17

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 >

A.

> Outer message

B.

> Outer message

Inner message

C.

> Inner message

D.

> Inner message

Outer message

Full Access
Question # 18

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 # 19

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 # 20

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 # 21

Refer to the code below:

01 new Promise((resolve, reject) = > {

02 const fraction = Math.random();

03 if (fraction > 0.5) reject( ' fraction > 0.5, ' + fraction);

04 resolve(fraction);

05 })

06 .then(() = > console.log( ' resolved ' ))

07 .catch((error) = > console.error(error))

08 .finally(() = > console.log( ' when am I called? ' ));

When does Promise.finally on line 08 get called?

A.

When rejected

B.

When resolved and settled

C.

When resolved

D.

When resolved or rejected

Full Access
Question # 22

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 # 23

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 # 24

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.

False negative

B.

True positive

C.

True negative

D.

False positive

Full Access
Question # 25

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 # 26

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 # 27

A developer needs the function personalizeWebsiteContent to run when the webpage is fully loaded (HTML and all external resources).

Which implementation should be used?

A.

Add a handler to the personalizeWebsiteContent script to handle the DOMContentLoaded event

B.

Add a listener to the window object to handle the load event

C.

Add a listener to the window object to handle the DOMContentLoaded event

D.

Add a handler to the personalizeWebsiteContent script to handle the load event

Full Access
Question # 28

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 # 29

A developer has an isDeg function that takes one argument, pts. They want to schedule the function to run every minute.

What is the correct syntax for scheduling this function?

A.

setInterval(isDeg( ' cat ' ), 60000);

B.

setInterval(isDeg, 60000, ' cat ' );

C.

setTimeout(isDeg, 60000, ' cat ' );

D.

setTimeout(isDeg( ' cat ' ), 60000);

Full Access
Question # 30

Given the code:

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

What is the value of copy?

A.

' [ " false " , false, null] '

B.

' [false, {}] '

C.

' [ " false " , false, undefined] '

D.

' [ " false " , {}] '

Full Access
Question # 31

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.

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

Full Access
Question # 32

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?

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

Full Access
Question # 33

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?

A.

0122

B.

0123

C.

0112

D.

0012

Full Access
Question # 34

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?

A.

Error: myFather.job is not a function

B.

undefined Developer

C.

John Developer

D.

John undefined

Full Access
Question # 35

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 # 36

A developer has a module that contains multiple functions.

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

A.

multi

B.

default

C.

all

D.

named

Full Access
Question # 37

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

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

Full Access
Question # 38

Given the code below:

let numValue = 1982;

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

A.

let strValue = numValue.toText();

B.

let strValue = String(numValue);

C.

let strValue = ' ' + numValue;

D.

let strValue = numValue.toString();

E.

let strValue = (String)numValue;

Full Access
Question # 39

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?

A.

Car 2 completed the race.

B.

Car 1 crashed on the race.

C.

Race is cancelled.

D.

Car 3 completed the race.

Full Access
Question # 40

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?

A.

4 2 1 5 3

B.

4 2 1 5 3

C.

1 4 2 3 5

D.

4 5 1 2 3

Full Access
Question # 41

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?

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

Full Access
Question # 42

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?

A.

node start

B.

npm start

C.

npm start server.js

D.

start server.js

Full Access
Question # 43

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?

A.

console.timeLog()

B.

console.trace()

C.

console.timeStamp()

D.

console.getTime()

Full Access
Question # 44

Given the HTML below:

< div >

< div id= " row-uc " > Universal Containers < /div >

< div id= " row-as " > Applied Shipping < /div >

< div id= " row-bt " > Burlington Textiles < /div >

< /div >

Which statement adds the priority-account CSS class to the Applied Shipping row?

A.

document.querySelectorAll( ' #row-as ' ).classList.add( ' priority-account ' );

B.

document.querySelector( ' #row-as ' ).classList.add( ' priority-account ' );

C.

document.querySelector( ' #row-as ' ).classes.push( ' priority-account ' );

D.

document.getElementById( ' row-as ' ).addClass( ' priority-account ' );

Full Access