Last Updated On : 17-Aug-2026
Salesforce Certified JavaScript Developer - JS-Dev-101 Practice Test
Prepare with our free Salesforce Certified JavaScript Developer - JS-Dev-101 sample questions and pass with confidence. Our Salesforce-JavaScript-Developer practice test is designed to help you succeed on exam day.
Salesforce 2026
Refer to the code below (corrected to use a template literal on line 08):
01 let car1 = new Promise((_, reject) = >
02 setTimeout(reject, 2000, " Car 1 crashed in " )
03 );
04 let car2 = new Promise(resolve = >
05 setTimeout(resolve, 1500, " Car 2 completed " )
06 );
07 let car3 = new Promise(resolve = >
08 setTimeout(resolve, 3000, " Car 3 completed " )
09 );
10
11 Promise.race([car1, car2, car3])
12 .then(value = > {
13 let result = `${value} the race.`;
14 })
15 .catch(err = > {
16 console.log( " Race is cancelled. " , err);
17 });
What is the value of result when Promise.race executes?
A. Car 3 completed the race.
B. Car 2 completed the race.
C. Race is cancelled.
D. Car 1 crashed in the race.
Explanation:
This question tests your understanding of Promise.race() and how it settles based on the first promise to settle, regardless of whether it resolves or rejects. Promise.race() returns a promise that settles with the result of the first promise in the iterable that settles. In this code, car2 is the fastest with a 1500ms delay, and it resolves. Therefore, Promise.race() resolves with the value of car2, which is "Car 2 completed". The .then() handler constructs the result string as "Car 2 completed the race.". The .catch() handler is not executed because the first settled promise resolves, not rejects.
Correct Option:
B. Car 2 completed the race. –
Correct. car2 has the shortest delay (1500ms) among the three promises. It resolves first with the value "Car 2 completed". Promise.race() resolves with this value, and the .then() handler creates the string "Car 2 completed the race." by interpolating the value into the template literal. This is the correct output because car2 settles first and resolves successfully.
Incorrect Options:
A. Car 3 completed the race. –
Incorrect. car3 has a delay of 3000ms, making it the slowest. Promise.race() only considers the first settled promise. Since car2 (1500ms) settles before car3 (3000ms), car3's value is ignored. The result uses the value from car2, not car3.
C. Race is cancelled. –
Incorrect. This message is logged only in the .catch() handler, which executes if the first settled promise rejects. However, car2 resolves first, so the promise chain enters the .then() handler, not the .catch() handler. This option would be correct only if car1 (which rejects) were the first to settle, but its delay is 2000ms, which is longer than car2's 1500ms.
D. Car 1 crashed in the race. –
Incorrect. car1 rejects after 2000ms, but car2 resolves at 1500ms, so car1 is not the first to settle. Promise.race() ignores car1 because it settles second. This option would be correct only if car1 were the first to settle, but it is not.
Reference:
MDN Web Docs – Promise.race() method
MDN Web Docs – Promise settling and race conditions
MDN Web Docs – Promise chaining and then/catch handlers
Salesforce Trailhead – JavaScript Essentials: Asynchronous Programming and Promise Methods
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?
A. super(size);
B. ship.size = size;
C. super.size = size;
D. this.size = size;
Explanation:
This question tests your understanding of class inheritance and the super keyword in JavaScript. When a subclass extends a parent class, the subclass constructor must call super() before using this. The super() call invokes the parent class constructor, passing the required arguments to initialize the parent's properties. In this case, FishingBoat extends Ship, and the Ship constructor expects a size parameter. The super(size) call passes the size argument to the parent constructor, setting this.size = size in the parent class. This ensures that the size property is correctly initialized, and the code displays the expected output.
Correct Option:
A. super(size); –
Correct. The super() call invokes the parent class (Ship) constructor with the size argument. The Ship constructor sets this.size = size. This is the required and correct way to initialize the parent class's properties in a subclass constructor. Without this call, the size property would be undefined.
Incorrect Options:
B. ship.size = size; –
Incorrect. There is no ship variable in this context. The parent class is accessed via super, not by a variable name. This would throw a ReferenceError because ship is not defined.
C. super.size = size; –
Incorrect. super is used to call the parent constructor or access parent methods, but it cannot be used to assign properties directly like super.size = size. The correct way to set parent properties is to call super() and let the parent constructor handle the assignment. This syntax is invalid and would not work.
D. this.size = size; –
Incorrect. While this would set the size property on the instance, it bypasses the parent class's constructor. The subclass should call super() to properly initialize the parent class. If super() is not called, it can lead to errors or incomplete initialization. Additionally, the Ship constructor's logic (if any) would be skipped, which is not the correct inheritance pattern.
Reference:
MDN Web Docs – super keyword in class constructors
MDN Web Docs – Class inheritance (extends)
MDN Web Docs – Constructor and parent class initialization
Salesforce Trailhead – JavaScript Essentials: Object-Oriented Programming and Classes
What are two unique features of fat-arrow functions compared to normal function definitions?
A. If the function has a single expression in the function body, the expression will be evaluated and implicitly returned.
B. The function uses the this from the enclosing scope.
C. The function receives an argument called parentThis, giving the enclosing lexical scope.
D. The function generates its own this making it useful for separating scope.
B. The function uses the this from the enclosing scope.
Explanation:
This question tests your understanding of the key differences between arrow functions (fat-arrow functions) and regular function declarations in JavaScript. Arrow functions have two primary unique features: they have implicit return when the function body contains a single expression (without curly braces), and they do not bind their own this; instead, they inherit this from the enclosing lexical scope. Regular functions, on the other hand, have their own this context depending on how they are called. These differences make arrow functions particularly useful for callbacks and scenarios where preserving the surrounding this is important.
Correct Options:
A. If the function has a single expression in the function body, the expression will be evaluated and implicitly returned. –
Correct. Arrow functions support concise body syntax: if the function body is a single expression without curly braces, the result of that expression is automatically returned without needing the return keyword. For example, const add = (a, b) => a + b; implicitly returns a + b. This is not possible with regular functions.
B. The function uses the this from the enclosing scope. –
Correct. Arrow functions do not have their own this binding. Instead, they capture the this value from the surrounding lexical scope at the time the arrow function is defined. This makes them ideal for use in callbacks where you want to preserve the this context of the enclosing function, avoiding the need for .bind(this) or const self = this.
Incorrect Options:
C. The function receives an argument called parentThis, giving the enclosing lexical scope. –
Incorrect. Arrow functions do not receive any special argument like parentThis. They capture this lexically from the enclosing scope automatically. There is no such parameter.
D. The function generates its own this making it useful for separating scope. –
Incorrect. Arrow functions do not generate their own this. This is the opposite of their behavior. Regular functions generate their own this based on how they are called, which can be useful for separating scope, but arrow functions do not. This statement describes regular functions, not arrow functions.
Reference:
MDN Web Docs – Arrow functions and implicit return
MDN Web Docs – Arrow functions and lexical this
MDN Web Docs – Function declarations and this binding
Salesforce Trailhead – JavaScript Essentials: Functions and Arrow Functions
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 ' );
D. console.log(10 / ' five ' );
Explanation:
This question tests your understanding of NaN (Not-a-Number) in JavaScript, specifically when it is produced by arithmetic operations or type conversions. NaN is returned when a mathematical operation fails to produce a valid number. parseInt() returns NaN when it cannot parse a string that does not start with a valid numeric character. Division by a non-numeric string also produces NaN because the string cannot be coerced to a number. Other operations like division by zero return Infinity, and valid numeric divisions return a number.
Correct Options:
B. console.log(parseInt('two')); –
Correct. The parseInt() function attempts to parse the string 'two' as an integer. Since 'two' does not start with a numeric character, parseInt() returns NaN. This is a common way to produce NaN when parsing invalid numeric strings.
D. console.log(10 / 'five'); –
Correct. The division operator (/) attempts to coerce both operands to numbers. The string 'five' cannot be converted to a number, so it becomes NaN. Any arithmetic operation involving NaN results in NaN. Therefore, 10 / 'five' evaluates to NaN.
Incorrect Options:
A. console.log(10 / 0); –
Incorrect. Division by zero in JavaScript returns Infinity (or -Infinity depending on the sign), not NaN. This is a valid numeric result in JavaScript's floating-point arithmetic. 10 / 0 evaluates to Infinity.
C. console.log(10 / Number('5')); –
Incorrect. Number('5') converts the string '5' to the number 5. The division 10 / 5 evaluates to 2, which is a valid number. This does not produce NaN.
Reference:
MDN Web Docs – NaN and arithmetic operations
MDN Web Docs – parseInt() and parsing strings
MDN Web Docs – Number() conversion and division operator
Salesforce Trailhead – JavaScript Essentials: Working with Numbers and 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. 03 if(arr.length == 0) { return 0; }
B. 04 result = result + current;
C. 02 arr.map((result, current) = > {
D. 05 return result;
Explanation:
This question tests your understanding of the Array.prototype.reduce() method and how to properly return the accumulated result from the reducer callback. The reduce() method expects the reducer function to return a value that becomes the new accumulator for the next iteration. In the given code, the reducer function on lines 03-05 is missing a return statement. Without a return, the function returns undefined for each iteration, causing the final result to be undefined (or NaN when added). To fix this, the reducer function must explicitly return the updated accumulator (e.g., return result + current; or return result += current;).
Correct Option:
D. 05 return result; –
Correct. The reducer function must return the accumulated value for the next iteration. On line 05, adding return result; ensures that the updated accumulator is returned after each iteration. The complete reducer would be (result, current) => { result += current; return result; }. This correctly returns the accumulated sum, and the reduce() method will return the final sum (with the initial value of 10).
Incorrect Options:
A. 03 if(arr.length == 0) { return 0; } –
Incorrect. This checks if the array is empty and returns 0, but this does not fix the missing return inside the reducer function. The reduce() method already handles empty arrays when an initial value is provided (it returns the initial value 10). Adding this check is unnecessary and does not address the core issue of the missing return inside the reducer.
B. 04 result = result + current; –
Incorrect. This changes the assignment syntax but still does not include a return statement. The reducer function still returns undefined because there is no explicit return. Without a return, the accumulator becomes undefined after the first iteration, leading to NaN or incorrect results.
C. 02 arr.map((result, current) => { –
Incorrect. This replaces reduce() with map(), which is not suitable for calculating a sum. map() returns a new array of the same length, not a single accumulated value. This would not produce the sum of the array elements and is the wrong method for this requirement.
Reference:
MDN Web Docs – Array.prototype.reduce() method
MDN Web Docs – Reducer callback return value
MDN Web Docs – Array.prototype.map() method
Salesforce Trailhead – JavaScript Essentials: Array Methods and Reduction
| Salesforce-JavaScript-Developer Exam Questions - Home | Previous |
| Page 3 out of 30 Pages |