Question 3 of 20
A developer wants to use a module called `DatePrettyPrint`. This module exports one default function called `printDate()`. How can a developer import and use the `printDate()` function?
Choose 1 answer
Question 4 of 20
Refer to the code below:
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),
07 exec('y', 500),
08 exec('z', 1000)
09 ]);
10 return `parallel is done: ${result1} ${result2} ${result3}`;
11 }
Which two statements correctly execute the `runParallel()` function?
Choose 2 answers
Question 6 of 20
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?
Choose 2 answers
Question 9 of 20
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. Given the code and the information the developer has, which code logs an error at boot time with an event?
Choose 1 answer
Question 10 of 20
A developer needs to test this function:
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?
Choose 2 answers
Question 11 of 20
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 'sku0000000008675309'?
Choose 1 answer
Question 12 of 20
A developer creates a class that represents a news story based on the requirements that a Story should have a body, author, and view count. The code is shown below:
01 class Story {
02 // Insert code here
03 this.body = body;
04 this.author = author;
05 this.viewCount = viewCount;
06 }
Which statement should be inserted in the placeholder on line 02 to allow for a variable to be set to a new instance of a story with the three attributes correctly populated?
Choose 1 answer
Question 13 of 20
Refer to the code below:
for (let number = 2; number <= 5; number += 1) {
// Insert code statement here
}
The developer needs to insert a code statement in the location shown. The code statement has these requirements:
1. Does not require an import
2. Logs an error when the Boolean statement evaluates to false
3. Works in both the browser and Node.js
Which statement meets these requirements?
Choose 1 answer
Question 15 of 20
The developer has a function that prints 'Hello' to an input name. To test this, the developer created a function that returns 'World'. However, the following snippet does not print 'Hello World':
01 const sayHello = (name) => {
02 console.log('Hello ', name);
03 };
04
05 const world = () => {
06 return 'World';
07 };
08
09 sayHello(world);
What can the developer do to change the code to print 'Hello World'?
Choose 1 answer
Question 17 of 20
Refer to the code below:
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 could a developer insert at the placeholder in line 02 to achieve this?
Choose 2 answers
Choose 2 answers
Question 18 of 20
Refer to the code below:
function createCounter() {
let count = 0;
return function() {
count += 1;
return count;
};
}
const counter = createCounter();
const counter2 = createCounter();
console.log(counter());
console.log(counter());
console.log(counter2());
console.log(counter());
What is the output of the above code?
Choose 1 answer
Question 19 of 20
Refer to the code below:
async function fetchData() {
return new Promise((resolve) => setTimeout(() => resolve('Data fetched'), 1000));
}
fetchData().then((data) => {
console.log(data);
});
console.log('Fetching data...');
What is the output of the above code?
Choose 1 answer
Question 20 of 20
Refer to the code below:
console.log('Start');
setTimeout(() => {
console.log('Timeout 1');
}, 0);
Promise.resolve().then(() => {
console.log('Promise 1');
});
console.log('End');
What is the output of the above code?
Choose 1 answer