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?
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?
Given the following code:
01 let x = null;
02 console.log(typeof x);
What is the output of line 02?
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 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 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?
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 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?
Which three browser specific APIs are available for developers to persist data between page loads?
function myFunction() {
a = a + b;
var b = 1;
}
myFunction();
console.log(a);
console.log(b);
Which statement is correct?
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?
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 >
HTML:
< p > The current status of an Order: < span id= " status " > In Progress < /span > < /p >
Which JavaScript statement changes ' In Progress ' to ' Completed ' ?
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?
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?
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 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 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 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?
Which statement allows a developer to update the browser navigation history without a page refresh?
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 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 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?
Given the code:
const copy = JSON.stringify([new String( ' false ' ), new Boolean(false), undefined]);
What is the value of copy?
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 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?
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?
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 developer has a module that contains multiple functions.
What kind of export should be leveraged so that multiple functions can be used?
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()?
Given the code below:
let numValue = 1982;
Which three code segments result in a correct conversion from number to string?
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?
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 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 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?
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?
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?