JavaScript-Developer-I Salesforce Certified JavaScript Developer (JS-Dev-101) Questions and Answers
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?
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 developer has two ways to write a function:
Option A:
01 function Monster() {
02 this.growl = () = > {
03 console.log( " Grr! " );
04 }
05 }
Option B:
01 function Monster() {};
02 Monster.prototype.growl = () = > {
03 console.log( " Grr! " );
04 }
After deciding on an option, the developer creates 1000 monster objects. How many growl methods are created with Option A and Option B?
Given the code:
const copy = JSON.stringify([new String( ' false ' ), new Boolean(false), undefined]);
What is the value of copy?
Given the JavaScript below:
01 function filterDOM(searchString){
02 const parsedSearchString = searchString & & searchString.toLowerCase();
03 document.querySelectorAll( ' .account ' ).forEach(account = > {
04 const accountName = account.innerHTML.toLowerCase();
05 account.style.display = accountName.includes(parsedSearchString) ? /* Insert code here */;
06 });
07 }
Which code should replace the placeholder comment on line 05 to hide accounts that do not match the search string?
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:
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 ' ), exec( ' y ' , ' 500 ' ), exec( ' z ' , ' 100 ' )]
07 );
08 return `parallel is done: ${result1}${result2}${result3}`;
09 }
Which two statements correctly execute runParallel()?
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 " ?
Refer to the code below:
01 const objBook = {
02 title: ' JavaScript ' ,
03 };
04 Object.preventExtensions(objBook);
05 const newObjBook = objBook;
06 newObjBook.author = ' Robert ' ;
What are the values of objBook and newObjBook respectively?
Refer to the code below:
01 let country = {
02 get capital() {
03 let city = Number( " London " );
04
05 return {
06 cityString: city.toString(),
07 }
08 }
09 }
Which value can a developer expect when referencing country.capital.cityString?
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?
Refer to the code below:
let strNumber = ' 12345 ' ;
Which code snippet shows a correct way to convert this string to an integer?
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?
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 developer is asked to fix some bugs reported by users. To do that, the developer adds a breakpoint for debugging.
01 function Car(maxSpeed, color) {
02 this.maxSpeed = maxSpeed;
03 this.color = color;
04 }
05 let carSpeed = document.getElementById( ' carSpeed ' );
06 debugger;
07 let fourWheels = new Car(carSpeed.value, ' red ' );
When the code execution stops at the breakpoint on line 06, which two types of information are available in the browser console?
Refer to the code:
01 console.log( ' Start ' );
02 Promise.resolve( ' Success ' ).then(function(value) {
03 console.log( ' Success ' );
04 });
05 console.log( ' End ' );
What is the output after the code executes successfully?
01 function changeValue(obj) {
02 obj.value = obj.value / 2;
03 }
04 const objA = {value: 10};
05 const objB = objA;
06
07 changeValue(objB);
08 const result = objA.value;
What is the value of result after the code executes?
Refer to the code below:
const searchText = ' Yay! Salesforce is amazing! ' ;
let result1 = searchText.search(/sales/i);
let result2 = searchText.search(/sales/);
console.log(result1);
console.log(result2);
After running this code, which result is displayed on the console?
Given the code below:
let numValue = 1982;
Which three code segments result in a correct conversion from number to string?
Given the following code:
01 let x = null;
02 console.log(typeof x);
What is the output of line 02?
Refer to the following object:
const dog = {
firstName: ' Beau ' ,
lastName: ' Boo ' ,
get fullName() {
return this.firstName + ' ' + this.lastName;
}
};
How can a developer access the fullName property for dog?
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?
Considering type coercion, what does the following expression evaluate to?
true + ' 13 ' + NaN
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 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?
Refer to the code below:
01 function myFunction(reassign) {
02 let x = 1;
03 var y = 1;
04
05 if (reassign) {
06 let x = 2;
07 var y = 2;
08 console.log(x);
09 console.log(y);
10 }
11
12 console.log(x);
13 console.log(y);
14 }
What is displayed when myFunction(true) is called?
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?
Given two expressions var1 and var2, what are two valid ways to return the concatenation of the two expressions and ensure it is data type string?
const str = ' Salesforce ' ;
Which two statements result in the word " Sales " ?
Corrected code:
let a = " * " ;
let b = " ** " ;
// x = 3;
console.log(a);
What is displayed when the code executes?
Refer to the following object:
01 const cat = {
02 firstName: ' Fancy ' ,
03 lastName: ' Whiskers ' ,
04 get fullName(){
05 return this.firstName + ' ' + this.lastName;
06 }
07 };
How can a developer access the fullName property for cat?
A developer needs the function personalizeWebsiteContent to run when the webpage is fully loaded (HTML and all external resources).
Which implementation should be used?
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?
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?