Total 221 Questions
Last Updated On : 18-Jun-2025
Preparing with JavaScript-Developer-I practice test is essential to ensure success on the exam. This Salesforce SP25 test allows you to familiarize yourself with the JavaScript-Developer-I exam questions format and identify your strengths and weaknesses. By practicing thoroughly, you can maximize your chances of passing the Salesforce certification spring 2025 release exam on your first attempt. Surveys from different platforms and user-reported pass rates suggest JavaScript-Developer-I practice exam users are ~30-40% more likely to pass.
A test has a dependency on database. query. During the test, the dependency is replaced with an object called database with the method, Calculator query, that returns an array. The developer does not need to verify how many times the method has been called. Which two test approaches describe the requirement?
(Choose 2 answers)
A. White box
B. Stubbing
C. Black box
D. Substitution
Explanation:
Replacing the database.query dependency with a stand-in object that returns a fixed array without inspecting its internal behavior or verifying invocation counts is characteristic of stubbing and black-box testing. Stubbing provides a lightweight test double that returns predetermined data. Black-box testing focuses on inputs and outputs, ignoring the internal implementation and call frequency. White-box testing would require awareness of internal logic and verifying interactions, which is not needed here. Substitution is not a formal testing term in mainstream methodologies. Therefore, the appropriate approaches are stubbing to replace dependencies and black-box testing to validate behavior purely by the returned data.
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 number in the array, The test passes:
Let res = sum2([1, 2, 3 ]) ;
console.assert(res === 6 );
Res = sum3([ 1, 2, 3, 4]);
console.assert(res=== 6);
A different developer made changes to the behavior of sum3 to instead sum all of the numbers present in the array. The test passes:
Which two results occur when running the test on the updated sum3 function?
(Choose 2 answers)
A. The line 02 assertion passes.
B. The line 02 assertion fails
C. The line 05 assertion passes.
D. The line 05 assertion fails.
Explanation:
With the updated sum3 that sums all elements, calling sum3([1,2,3]) still returns 6, so the first console.assert(res === 6) passes. However, sum3([1,2,3,4]) now returns 10, not 6, so the second assertion fails. Thus, line 02 succeeds (A), and line 05 fails (D). This highlights the importance of writing tests that capture intended behavior changes: when functionality broadens from summing only the first three items to summing the entire array, existing tests may no longer validate correct behavior for all inputs.
Refer to the code below:
01 const exec = (item, delay) =>{
02 new Promise(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)
A. Async runParallel () .then(data);
B. runParallel ( ). done(function(data){
return data;
});
C. runParallel () .then(data);
D. runParallel () .then(function(data)
return data
Explanation:
Because runParallel() is an async function, it returns a Promise. You consume its result via the Promise API’s .then(...) handler. Options C and D correctly call runParallel() and attach a .then callback to process its resolved value. Option A incorrectly prefixes with Async, which isn’t valid syntax for invocation. Option B uses .done(...), a non-standard Promise method (found in some libraries but not native JavaScript). Always use .then(...) or await to handle async function results in modern JavaScript.
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 the developer implement the request?
A. Let arr1 = arr.filter(( val) => ( return val > 15 )) .map (( num) => ( return num *2 ))
B. Let arr1 = arr.mapBy (( num) => ( return num *2 )) .filterBy (( val ) => return val > 15 )) ;
C. Let arr1 = arr.map((num) => num*2). Filter (( val) => val > 15);
D. Let arr1 = arr.map((num) => ( num *2)).filterBy((val) => ( val >15 ));
Explanation:
You first double each grade using Array.prototype.map(), producing [14,16,10,16,18]. Then you filter scores above 15 with Array.prototype.filter(), yielding [16,16,18]. This chaining ensures the mapping happens before filtering. Option A reverses the order (filter then map), B and D use non-standard methods (mapBy/filterBy), which don’t exist in vanilla JavaScript. Option C correctly leverages built-in map and filter methods in the proper sequence to meet the teacher’s requirements.
Given the code below:
const copy = JSON.stringify([ new String(‘ false ’), new Bollean( false ), undefined ]);
What is the value of copy?
A. -- [ \”false\” , { } ]--
B. -- [ false, { } ]--
C. -- [ \”false\” , false, undefined ]--
D. - [ \”false\” ,false, null ]--
Explanation:
When JSON.stringify processes an array:
1. String object: new String('false') is coerced to the primitive "false", so it becomes the JSON string "false".
2. Boolean object: new Boolean(false) is coerced to the primitive false, so it becomes the JSON boolean false.
3. Undefined: Array elements that are undefined are serialized as null in JSON.
Putting this together yields the JSON text ["false",false,null].
Universal Containers recently launched its new landing page to host a crowd-funding campaign. The page uses an external library to display some third-party ads. Once the page is fully loaded, it creates more than 50 new HTML items placed randomly inside the DOM, All the elements includes the same ad-library-item class, They are hidden by default, and they are randomly displayed while the user navigates through the page.
A. Use the DOM inspector to prevent the load event to be fired.
B. Use the browser to execute a script that removes all the element containing the class ad-library-item.
C. Use the DOM inspector to remove all the elements containing the class ad-library-item.
D. Use the browser console to execute a script that prevents the load event to be fired.
Explanation:
Since the ads are generated dynamically after load and may reappear randomly, manually deleting them via the DOM inspector (option C) is impractical and one-off. Preventing the load event (options A and D) could break page functionality. Instead, injecting a small JavaScript snippet in the browser console to select all elements with .ad-library-item and remove them ensures you can rerun it at any time to clean up all current and newly inserted ads. For example:
document.querySelectorAll('.ad-library-item').forEach(el => el.remove());
Given HTML below:
1. Universal Container
2. Applied Shipping
3. Burlington Textiles
Which statement adds the priority = account CSS class to the universal Containers row ?
A. Document .querySelector(‘#row-uc’).classes.push(‘priority-account’);
B. Document .queryElementById(‘row-uc’).addclass(‘priority-account’);
C. Document .querySelector(‘#row-uc’).classList.add(‘priority-account’);
D. Document .querySelectorALL(‘#row-uc’).classList.add(‘priority-account’);
Explanation:
The document.querySelector('#row-uc') call returns the
Which two code snippets show working examples of a recursive function?
(Choose 2 answers)
A. Let countingDown = function(startNumber) {
If ( startNumber >0) {
console.log(startNumber) ;
return countingDown(startNUmber);
} else {
return startNumber;
}};
B. Function factorial ( numVar ) {
If (numVar < 0) return;
If ( numVar === 0 ) return 1;
return numVar -1;
C. Const sumToTen = numVar => {
If (numVar < 0)
Return;
return sumToTen(numVar + 1)};
D. Const factorial =numVar => {
If (numVar < 0) return;
If ( numVar === 0 ) return 1;
Explanation:
Option A shows a proper recursive countdown function that:
Has a base case (startNumber <= 0)
Makes a recursive call with a modified parameter (startNumber - 1)
Actually progresses toward the base case
Option D shows a correct factorial function that:
Handles edge cases (negative numbers and 0)
Recursively calls itself with numVar - 1
Combines results with multiplication (numVar * factorial(numVar - 1))
Refer to the code below:
new Promise((resolve, reject) => {
const fraction = Math.random();
if( fraction >0.5) reject("fraction > 0.5, " + fraction);
resolve(fraction);
})
.then(() =>console.log("resolved"))
.catch((error) => console.error(error))
.finally(() => console.log(" when am I called?"));
When does Promise.finally on line 08 get called?
A. When rejected
B. When resolved and settled
C. When resolved
D. When resolved or rejected
Explanation:
The .finally() method of a Promise is guaranteed to execute once the promise is settled, regardless of whether it was fulfilled or rejected. It does not receive any arguments, and is designed for cleanup tasks (such as hiding loading indicators) that must run in either case. In the code above, if fraction > 0.5, the promise is rejected and the .catch() handler runs first; whether through .then() or .catch(), once that branch completes, .finally() executes. Thus, line 08 always logs "when am I called?" after the promise has either resolved or rejected.
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 ?
A. Returns 0
B. Throws an error
C. Returns 10
D. Returns NaN
Explanation:
When you call Array.prototype.reduce on an empty array with an initial value provided (10), the reducer function is never invoked, and reduce immediately returns that initial value. In this snippet, because arr is empty, reduce skips the callback and yields 10. No error is thrown, and you don’t get NaN (which would happen if you’d attempted arithmetic without an initial value). Always remember: with an initial accumulator, reduce guarantees a return value even for empty arrays.
Page 3 out of 23 Pages |
JavaScript-Developer-I Practice Test Home | Previous |