Last Updated On : 20-May-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:
01 let car1 = new promise((_, reject) =>
02 setTimeout(reject, 2000, “Car 1 crashed in”));
03 let car2 = new Promise(resolve => setTimeout(resolve, 1500, “Car 2
completed”));
04 let car3 = new Promise(resolve => setTimeout (resolve, 3000, “Car 3
Completed”));
05 Promise.race([car1, car2, car3])
06 .then(value => (
07 let result = $(value) the race. `;
08 ))
09 .catch( arr => (
10 console.log(“Race is cancelled.”, err);
11 ));
What is the value of result when Promise.race executes?
A. Car 3 completed the race.
B. Car 1 crashed in the race.
C. Car 2 completed the race.
D. Race is cancelled.
Explanation:
The Promise.race() method takes an iterable (like an array) of promises and returns a single promise. This returned promise settles (either fulfills or rejects) as soon as one of the promises in the iterable settles, with the value or reason from that first settled promise.
Let's analyze the timers for each promise:
car1 (line 01): This promise is set to reject after 2000ms (2 seconds) with the value "Car 1 crashed in".
car2 (line 03): This promise is set to resolve after 1500ms (1.5 seconds) with the value "Car 2 completed".
car3 (line 04): This promise is set to resolve after 3000ms (3 seconds) with the value "Car 3 completed".
The execution of Promise.race([car1, car2, car3]) will be determined by which promise settles first.
car2 resolves successfully after 1500ms.
car1 rejects after 2000ms.
car3 resolves after 3000ms.
Since car2 has the shortest timer (1500ms < 2000ms < 3000ms), it settles first. Promise.race() will adopt the state of this first settled promise, which is a fulfillment with the value "Car 2 completed".
Therefore, the .then() handler on line 06 will execute, receiving the value "Car 2 completed". The variable result will be set to the string "Car 2 completed the race." (Note: The code uses a template literal `$(value) the race.`; which is syntactically incorrect—it should be `${value} the race.`;—but the intent is clear for the purpose of the question).
Why the other options are wrong:
A. Car 3 completed the race: This is incorrect because car3 has the longest timer (3000ms) and will be the last to settle. Promise.race() does not wait for it.
B. Car 1 crashed in the race: This is incorrect because while car1 does reject, it does so after 2000ms. car2 resolves 500ms earlier, so its resolution is the one that wins the "race".
D. Race is cancelled.: This is the message that would be logged in the .catch() handler. The .catch() handler would only run if the first settled promise was a rejection. Since the first settled promise (car2) was a fulfillment, the .then() handler runs instead of the .catch() handler.
developer uses the code below to format a date.
After executing, what is the value of formattedDate?
A.
A. May 10, 2020
B. June 10, 2020
C. October 05, 2020
D. November 05, 2020
Refer to the following code:
Which two statement could be inserted at line 17 to enable the function call on line 18? Choose 2 answers
A. Object.assign (leo, tony);
B. Object.assign (leo. Tiger);
C. leo.roar = () => { console.log('They\'re pretty good!'); );
D. leo.prototype.roar = ( ) =>( console.log('They\'re pretty good!'); };
C. leo.roar = () => { console.log('They\'re pretty good!'); );
Refer to the following code:
What is the value of output on line 11?
A.
[1, 2]
B.
[‘’foo’’, ‘’bar’’]
C.
[
D.
An error will occur due to the incorrect usage of the for…of statement on line 07.
An error will occur due to the incorrect usage of the for…of statement on line 07.
is below:
<" input type="”file”" onchange="”previewFile()" ">
< img src=”” height=”200” alt=”Image Preview…”/>
The JavaScript portion is:
01 functionpreviewFile(){
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 }
In lines 04 and 08, which code allows the user to select an image from their local computer , and to display the image in the browser?
A. 04 const reader = new File(); 08 if (file) URL.createObjectURL(file);
B. 04 const reader = new FileReader(); 08 if (file) URL.createObjectURL(file);
C. 04 const reader = new File(); 08 if (file) reader.readAsDataURL(file);
Explanation:
FileReader is the correct API to read local files selected by a user via < input type= " file" >.
reader.readAsDataURL(file) reads the file as a Base64-encoded Data URL, which can be assigned directly to an src attribute to display the image.
The "load" event listener ensures that once the file is fully read, reader.result contains the file’s data, which is then used for preview.
So the full working version is:
function previewFile() {
const preview = document.querySelector('img');
const file = document.querySelector('input[type=file]').files[0];
const reader = new FileReader(); // ✅ correct object
reader.addEventListener("load", () => {
preview.src = reader.result; // ✅ set preview
}, false);
if (file) {
reader.readAsDataURL(file); // ✅ convert file into Data URL
}
}
❌ Why Other Options Are Wrong
A. const reader = new File(); → ❌ File is not used this way; it represents file objects, not readers. URL.createObjectURL(file) can create blob URLs, but then you don’t need FileReader at all (and the snippet relies on reader.result).
C. const reader = new File(); + reader.readAsDataURL(file) → ❌ Invalid because File objects don’t have .readAsDataURL(). That’s only for FileReader.
📖 Reference:
MDN: FileReader
MDN: readAsDataURL()
💡 Quick Exam Tip:
If you see reader.result → always think FileReader + readAsDataURL() for image previews.
| Salesforce-JavaScript-Developer Exam Questions - Home | Previous |
| Page 7 out of 45 Pages |