JavaScript-Developer-I Salesforce Certified JavaScript Developer JS-Dev-101 Questions and Answers
myArraym can have one level, two levels, or more levels.
Which statement flattens myArray when it can be arbitrarily nested?
A developer wants to leverage a module to print a price in pretty format, and has imported a method as shown below:
Import printPrice from ‘/path/PricePrettyPrint.js’;
Based on the code, what mustbe true about the printPrice function of the PricePrettyPrint module for this import to work ?
Cloud Kicks has a class to represent items for sale in an online store, as shown below:
Class Item{
constructor (name, price){
this.name = name;
this.price = price;
}
formattedPrice(){
return ‘s’ + String(this.price);}}
A new business requirement comes in that requests a ClothingItem class that should have all of
the properties and methods of the Item class but will also have properties that are specific to
clothes.
Which line of code properly declares the clothingItem class such that it inherits from
Item?
A developer at Universal Containers is creating their new landing pagebased on HTML, CSS, and JavaScript. The website includes multiple external resources that are loaded when the page is opened.
To ensure that visitors have a good experience, a script named personalizeWebsiteContent needs to be executed when the webpage isloaded and there is no need to wait for the resources to be available.
Which statement should be used to call personalizeWebsiteContent based on the above business requirement?
Which code statement correctly retrieves and returns an object from localStorage?
Refer of the string below:
Const str = ‘sa;esforce’=;
Which two statement result in the word ' Sale ' ?
Choose 2 answers
Teams at Universal Containers (UC) work on multiple JavaScript projects at the same time.
UC is thinking about reusability and how each team can benefit from the work of others.
Going open-source or public is not an option at this time.
Which option is available to UC with npm?
A developer at Universal Containers is creating their 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 when the webpage is fully loaded (HTML content and all related files), in order to do some custom initializations.
Which implementation should be used to call Fe:s:-a;::eHec5;te::.-.ter.: based on the business requirement above?
A developer has the following array of student test grades:
Let arr = [ 7, 8, 5, 8, 9 ];
The Teacher wants to double each score and then see an array of the students
who scored more than 15 points.
How should thedeveloper implement the request?
A developer creates a simple webpage with an input field. When a user enters text in
the inputfield and clicks the button, the actual value of the field must be displayed in the
console.
Here is the HTML file content:
< input type =” text” value=”Hello” name =”input” >
< button type =”button” > Display < /button >
The developer wrote the javascript codebelow:
Const button = document.querySelector(‘button’);
button.addEvenListener(‘click’, () = > (
Const input = document.querySelector(‘input’);
console.log(input.getAttribute(‘value’));
When the user clicks the button, the output is always “Hello”.
What needs to be done make this code work as expected?
A developer is creating a simple webpage with a button. When a userclicks 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 functionlisten(event) {
02 alert ( ‘Hey! I am John Doe’) ;
03 button.addEventListener (‘click’, listen);
Which two code lines make this code work as required?
Choose 2 answers
Refer to the codebelow:
function foo () {
const a =2;
function bat() {
console.log(a);
}
return bar;
}
Why does the function bar have access to variable a ?
Universal Containers (UC) notices that its application that allows users to search for
accounts makes a network request each time a key is pressed. This results in too many
requests for the server to handle.
● Address this problem, UC decides to implement a debounce function on string change
handler.
What are three key steps to implement this debounce function?
Choose 3 answers:
Refer to the code below:
Let foodMenu1 = [‘pizza’, ‘burger’, ‘French fries’];
Let finalMenu = foodMenu1;
finalMenu.push(‘Garlic bread’);
What is the value of foodMenu1 after the code executes?
Refer to the following array:
Let arr = [1, 2, 3, 4, 5];
Which three options result in x evaluating as [1,2]?
Choose 3 answer
Refer to the following code:
01 function Tiger(){
02this.Type = ‘Cat’;
03 this.size = ‘large’;
04 }
05
06 let tony = new Tiger();
07 tony.roar = () = > {
08 console.log(‘They\’re great1’);
09 };
10
11 function Lion(){
12 this.type = ‘Cat’;
13 this.size = ‘large’;
14 }
15
16 let leo = new Lion();
17 //Insertcode here
18 leo.roar();
Which two statements could be inserted at line 17 to enable the function call on line 18?
Choose 2 answers.
A developer wrote the following code to test a sum3 function that takes in an array of numbers and returns the sum of the first three numbers in the array, and the test passes.
A different developer made changes to the behavior of sum3 to instead sum only the first two numbers present in the array.

Which two results occur when running this test on the updated sum3 function?
Choose 2 answers
Refer to the code snippet below:
Let array = [1, 2, 3, 4, 4, 5, 4, 4];
For (let i =0; i < array.length; i++)
if (array[i] === 4) {
array.splice(i, 1);
}
}
What is the value of array after the code executes?
In the browser, the window object is often used to assign variables that require the broadest scope in an application Node.js application does not have access to the window object by default.
Which two methods areused to address this ?
Choose 2 answers
Refer to the following code block:
class Animal{
constructor(name){
this.name = name;
}
makeSound(){
console.log(`${this.name} ismaking a sound.`)
}
}
class Dog extends Animal{
constructor(name){
super(name)
this.name = name;
}
makeSound(){
console.log(`${this.name} is barking.`)
}
}
let myDog = new Dog( ' Puppy ' );
myDog.makeSound();
What is the console output?
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 teamhas already built using HTML, CSS, and
JavaScript.
Which three benefits of Node.js can the developer use to persuade their manager?
Choose 3 answers:
Refer to the code below:

Considering that JavaScript is single-threaded, what is the output of line 08 after the code executes?
A developer initiates a server with the file server,js and adds dependencies in the source codes package,json that are required to run the server.
Which command should the developer run to start the server locally?
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 needsthe folder location that the code executes from.
Which global variable can be used in the script?
A developer is leading the creation of a new browser application that will serve a single
page application. The team wants to use a new web framework Minimalsit.js.The Lead
developer wants to advocate for a more seasoned web framework that already has a
community around it.
Which two frameworks should the lead developer advocate for?
Choose 2 answers
A developer wants to use a try...catch statement to catch any error that countSheep () may throw and pass it to a handleError () function.
What is the correct implementation of the try...catch?
A)

B)

C)

D)

Given the code below:
const delay = sync delay = > {
Return new Promise((resolve, reject) = > {
setTimeout (resolve,delay);});};
const callDelay =async () = > {
const yup =await delay(1000);
console.log(1);
What is logged to the console?
A developer implements and calls the following code when an application state change occurs:
Const onStateChange =innerPageState) = > {
window.history.pushState(newPageState, ‘ ’, null);
}
If the back button is clicked after this method is executed, what can a developer expect?
Given the following code:
document.body.addEventListener(‘ click ’, (event) = > {
if (/* CODE REPLACEMENT HERE */) {
console.log(‘button clicked!’);
)
});
Which replacement for the conditional statement on line 02 allows a developer to
correctly determine that a button on page is clicked?
Refer to the code below:
Function Person(firstName, lastName, eyecolor) {
this.firstName =firstName;
this.lastName = lastName;
this.eyeColor = eyeColor;
}
Person.job = ‘Developer’;
const myFather = new Person(‘John’, ‘Doe’);
console.log(myFather.job);
What is the output after the code executes?
Consider type coercion, what does the following expression evaluate to?
True + 3 + ‘100’ + null
A developer creates a simple webpage with an input field. When a user enters text in the input field and clicks the button, the actual value of the field must be displayedin the console.
Here is the HTML file content:
< input type =” text” value=”Hello” name =”input” >
< button type =”button” > Display < /button > The developer wrote the javascript code below:
Const button = document.querySelector(‘button’);
button.addEvenListener(‘click’, () = > (
Const input = document.querySelector(‘input’);
console.log(input.getAttribute(‘value’));
When the user clicks the button, the output is always “Hello”.
What needs to be done to make this code work as expected?
A developer writers the code below to calculate the factorial of a given number.
Function factorial(number) {
Return number + factorial(number -1);
}
factorial(3);
What is the resultof executing line 04?
Refer to the code below:
< html lang=”en” >
< table onclick=”console.log(Table log’);” >
< tr id=”row1” >
< td > Click me! < /td >
< /tr >
< table >
< script >
functionprintMessage(event) {
console.log(‘Row log’);
}
Let elem = document.getElementById(‘row1’);
elem.addEventListener(‘click’, printMessage, false);
< /script >
< /html >
Which code change should be made for the console to log only Row log when ‘Click me! ’ is
clicked?
Which statement accurately describes the behaviour of the async/ await keyworks ?
Refer to the code below:
function changeValue(param) {
Param =5;
}
Let a =10;
Let b =5;
changeValue(b);
Const result = a+ “ - ”+ b;
What is the value of result when code executes?
A developer wrote a fizzbuzz function thatwhen 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 or 5.
Whichtwo test cases will properly test scenarios for the fizzbuzz function?
Choose 2 answers
Refer to the code below:

What is the output of this function when called with an empty array?
Refer to the code below:

Which value can a developer expect when referencing country,capital,cityString?
Given the code below:
Which three code segments result in a correct conversion from number to string? Choose 3 answers
Considering type coercion, what does the following expression evaluate to?
True + ‘13’ + NaN
Refer to the code below:
01 const exec = (item, delay) = > {
02 newPromise(resolve = > setTimeout( () = > resolve(item), delay)),
03 async function runParallel() {
04 Const (result1, result2, result3) = await Promise.all{
05 [exec (‘x’, ‘100’) , exec(‘y’, 500), exec(‘z’, ‘100’)]
06 );
07 return `parallel is done: $(result1)$(result2)$(result3)`;
08 }
}
}
Which two statements correctly execute the runParallel () function?
Choose 2 answers
Refer to the code below:
Const myFunction = arr = > {
Return arr.reduce((result, current) = > {
Return result = current;
}, 10};
}
What is the output of this function when called with an empty array ?
Refer to code below:
Let first = ‘who’;
Let second = ‘what’;
Try{
Try{
Throw new error(‘Sad trombone’);
}catch (err){
First =’Why’;
}finally {
Second =’when’;
} catch (err) {
Second =’Where’;
}
What are the values for first and second once the code executes ?
Refer to the code:

Given the code above, which three properties are set for pet1? Choose 3 answers
Refer to the code below:
const car = {
price:100,
getPrice:function(){
return this.price;
}
};
const customCar = Object.create(car);
customCar.price = 70;
delete customCar.price;const result = customCar.getPrice();
Whatis the value of result after the code executes?
A developer receives a comment from the Tech Lead that the code given below has
error:
const monthName = ‘July’;
const year = 2019;
if(year === 2019) {
monthName =‘June’;
}
Which line edit should be made to make this code run?
Given the following code:
let x = null;
console.log(typeof x);
What is the output?
Refer to the code below:

Which replacement for the conditionalstatement on line 02 allows a developer to correctly determine
that a specific element, myElement on the page had been clicked?
At Universal Containers, every team has its own way of copyingJavaScript objects. The code snippet shows an Implementation from one team:

What is the output of the code execution?
A developer copied a JavaScript object:

How does the developer access dan ' s forstName,lastName? Choose 2 answers
Refer to code below:
Let productSKU = ‘8675309’ ;
A developer has a requirement to generate SKU numbers that are always 19 characters lon,
starting with ‘sku’, and padded with zeros.
Which statement assigns the values sku0000000008675309 ?
A class was written to represent items for purchase in an online store, and a secondclass
Representing items that are on sale at a discounted price. THe constructor sets the name to the
first value passed in. The pseudocode is below:
Class Item {
constructor(name, price) {
… // Constructor Implementation
}
}
Class SaleItem extends Item {
constructor (name, price, discount) {
...//Constructor Implementation
}
}
There is a new requirement for a developer to implement a description method that will return a
brief description for Item and SaleItem.
Let regItem =new Item(‘Scarf’, 55);
Let saleItem = new SaleItem(‘Shirt’ 80, -1);
Item.prototype.description = function () { return ‘This is a ’ + this.name;
console.log(regItem.description());
console.log(saleItem.description());
SaleItem.prototype.description = function () { return ‘This is a discounted ’ +
this.name; }
console.log(regItem.description());
console.log(saleItem.description());
What is the output when executing the code above ?
Refer to the code below:
const event = new CustomEvent(
//Missing Code
);
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
A developer is wondering whether to use, Promise.then or Promise.catch, especially
when a Promise throws an error?
Which two promises are rejected?
Which 2 are correct?
A developer wants to use a module called DataPrettyPrint. This module exports one default functioncalled printDate ().
How can a developer import and use the printDate() function?
A)

B)

C)

D)




