Last Updated On : 17-Jul-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
Console logging methods that allow string substitution:
A. message
B. log
C. assert
D. nfo
E. error
C. assert
D. nfo
E. error
Explanation:
This question tests your knowledge of Console API methods that support string substitution using format specifiers (e.g., %s, %d, %f, %o). Several console methods allow you to use substitution patterns in the first argument, followed by values to replace the placeholders. The console.log(), console.assert(), console.info(), and console.error() methods all support string substitution. console.message() is not a valid console method in JavaScript, so it does not support string substitution.
Correct Options:
B. log –
Correct. console.log() supports string substitution using format specifiers like %s, %d, %o, etc. For example, console.log('Hello %s', 'World') outputs "Hello World".
C. assert –
Correct. console.assert() supports string substitution when a message is provided as the second argument. For example, console.assert(false, 'Value is %d', 42) will log an error with the substituted message.
D. info –
Correct. console.info() supports string substitution just like console.log(). It is an alias for console.log() in many browsers and supports the same formatting capabilities.
E. error –
Correct. console.error() supports string substitution. It outputs an error message to the console and can use format specifiers for substitution, similar to console.log().
Incorrect Options:
A. message –
Incorrect. There is no console.message() method in JavaScript. The Console API does not include a message method. This would throw a TypeError because console.message is undefined. Therefore, it does not support string substitution.
Reference:
MDN Web Docs – Console API and string substitution
MDN Web Docs – console.log() with format specifiers
MDN Web Docs – console.assert(), console.info(), console.error()
Salesforce Trailhead – JavaScript Essentials: Debugging with Console Methods
Corrected code:
let obj = {
foo: 1,
bar: 2
};
let output = [];
for (let something in obj) {
output.push(something);
}
console.log(output);
What is the output of line 11?
A. [ " bar " , " foo " ]
B. [1, 2]
C. [ " foo " , " bar " ]
D. [ " foo:1 " , " bar:2 " ]
Explanation:
This question tests your understanding of the for...in loop in JavaScript and how it iterates over an object's enumerable properties. The for...in loop iterates over the keys (property names) of an object, not the values. For the object { foo: 1, bar: 2 }, the loop will iterate over the keys "foo" and "bar". The output array will contain these keys as strings in the order they were added (which is generally the order of insertion). Therefore, the output is ["foo", "bar"].
Correct Option:
C. ["foo", "bar"] –
Correct. The for...in loop iterates over the enumerable property names (keys) of the object. The keys of obj are "foo" and "bar". The loop pushes each key string into the output array. The order is typically the order of insertion, which is "foo" followed by "bar". Therefore, console.log(output) outputs ["foo", "bar"].
Incorrect Options:
A. ["bar", "foo"] –
Incorrect. While the keys are "foo" and "bar", the order in which they are iterated is typically the order of insertion. In this case, "foo" was defined first, so it appears first. Unless the environment iterates in a different order (which is not guaranteed), the expected output is ["foo", "bar"], not ["bar", "foo"].
B. [1, 2] –
Incorrect. This would be the output if the loop iterated over the values of the object. However, for...in iterates over keys, not values. To get values, you would use Object.values(obj) or for...of on Object.values(obj).
D. ["foo:1", "bar:2"] –
Incorrect. This would be the output if the loop concatenated the key and value into a single string. However, for...in only provides the key; it does not automatically include the value. The loop pushes only the key (something), not a combined string.
Reference:
MDN Web Docs – for...in loop and object iteration
MDN Web Docs – for...in vs for...of
MDN Web Docs – Object.keys() and property enumeration
Salesforce Trailhead – JavaScript Essentials: Iteration and Objects
A developer wants to catch any error that countSheep() may throw and pass it to handleError().
Which implementation is correct?
A. try {
setTimeout(function() {
countSheep();
}, 1000);
}
catch (e) {
handleError(e);
}
B. try {
countSheep();
} finally {
handleError(e);
}
C. try {
countSheep();
} handleError(e) {
catch(e);
}
D. setTimeout(function() {
try {
(Answer incomplete in option list.)
setTimeout(function() {
countSheep();
}, 1000);
}
catch (e) {
handleError(e);
}
Explanation:
This question tests your understanding of error handling with asynchronous operations in JavaScript. If countSheep() is executed inside a setTimeout, the try/catch block must be placed inside the callback function to catch errors that occur during the asynchronous execution. Placing try/catch outside setTimeout will not work because the callback runs after the try/catch block has already completed. The correct implementation uses setTimeout with try/catch inside the callback, ensuring that any error thrown by countSheep() is caught and passed to handleError(e).
Correct Option:
A.
javascript
setTimeout(function() {
try {
countSheep();
} catch (e) {
handleError(e);
}
}, 1000);
This is correct. The try/catch block is placed inside the setTimeout callback function. When countSheep() executes after the 1000ms delay, any error thrown will be caught by the catch block, which then calls handleError(e). This correctly handles errors that occur during the asynchronous execution of countSheep().
Incorrect Options:
B.
javascript
try {
countSheep();
} finally {
handleError(e);
}
Incorrect. The finally block executes regardless of whether an error is thrown. It does not have access to the error object e because finally does not receive the error parameter. Additionally, handleError(e) would throw a ReferenceError because e is not defined. This does not catch the error; it only executes cleanup code.
C.
javascript
try {
countSheep();
} handleError(e) {
catch(e);
}
Incorrect. This uses invalid syntax. The correct syntax for try/catch is try { ... } catch (e) { ... }. The handleError and catch(e) syntax is not valid in JavaScript. This would result in a syntax error.
D.
javascript
try {
setTimeout(function() {
countSheep();
}, 1000);
} catch (e) {
handleError(e);
}
Incorrect. The try/catch is placed outside the setTimeout. When setTimeout is called, it schedules the callback and returns immediately. The try/catch block completes before the callback executes. If countSheep() throws an error after 1000ms, it will occur outside the try/catch scope, resulting in an uncaught error.
Reference:
MDN Web Docs – try...catch statement and asynchronous code
MDN Web Docs – setTimeout and error handling
MDN Web Docs – Call stack and event loop
Salesforce Trailhead – JavaScript Essentials: Error Handling and Asynchronous Programming
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?
A. let res = fizzbuzz(3);
console.assert(res === ' buzz ' );
B. let res = fizzbuzz(15);
console.assert(res === ' fizzbuzz ' );
C. let res = fizzbuzz(NaN);
console.assert(isNaN(res));
D. let res = fizzbuzz(Infinity);
console.assert(res === ' ' );
console.assert(res === ' fizzbuzz ' );
D. let res = fizzbuzz(Infinity);
console.assert(res === ' ' );
Explanation:
This question tests your understanding of writing effective test cases for a function, specifically ensuring that test inputs and expected outputs are correctly matched. The fizzbuzz function has defined behavior for different types of inputs. For numbers divisible by both 3 and 5, it returns 'fizzbuzz'. For numbers divisible by neither, it returns an empty string ''. The test case for 15 correctly expects 'fizzbuzz'. The test case for Infinity correctly expects an empty string since it is not divisible by 3 or 5 in a meaningful way. The test case for 3 incorrectly expects 'buzz' (should be 'fizz'), and the test case for NaN is not clearly defined in the requirements.
Correct Options:
B. let res = fizzbuzz(15); console.assert(res === 'fizzbuzz'); –
Correct. The number 15 is divisible by both 3 and 5, so the function should return 'fizzbuzz'. This test case correctly verifies the combined condition and ensures the function handles multiples of both numbers correctly.
D. let res = fizzbuzz(Infinity); console.assert(res === ''); –
Correct. Infinity is not divisible by 3 or 5 in the usual sense, so the function should return an empty string ''. This test case verifies how the function handles a special numeric value like Infinity. This is a valid test scenario.
Incorrect Options:
A. let res = fizzbuzz(3); console.assert(res === 'buzz'); –
Incorrect. The number 3 is divisible by 3, so the function should return 'fizz', not 'buzz'. This test case has the wrong expected output and would fail, making it an invalid test for the function's behavior.
C. let res = fizzbuzz(NaN); console.assert(isNaN(res)); –
Incorrect. The requirements do not specify how the function should handle NaN. It is not divisible by 3 or 5, so it could return an empty string, but the test expects NaN. Since the behavior is not defined, this is not a proper test case based on the given requirements.
Reference:
MDN Web Docs – console.assert() method for testing
MDN Web Docs – Testing and debugging strategies
MDN Web Docs – Infinity and NaN handling
Salesforce Trailhead – JavaScript Essentials: Testing and Debugging Functions
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?
A. Start
Success
End
B. Start
End
Success
C. End
Start
Success
D. Success
Start
End
End
Success
Explanation:
This question tests your understanding of the JavaScript event loop, microtasks, and the execution order of synchronous versus asynchronous code. The console.log('Start') on line 01 executes synchronously. The Promise.resolve().then() schedules a microtask that logs 'Success' to the microtask queue. The console.log('End') on line 05 executes synchronously before the microtask is processed. Once the call stack is empty, the event loop processes the microtask and logs 'Success'. The final output is 'Start', 'End', 'Success'.
Correct Option:
B.
text
Start
End
Success
This is correct. Synchronous code runs first: 'Start' is logged, then the promise's .then() callback is scheduled as a microtask, and 'End' is logged. After the synchronous code completes, the microtask is executed, logging 'Success'. The output order is Start, End, Success.
Incorrect Options:
A.
text
Start
Success
End
Incorrect. This would be the output if the promise resolved synchronously or if the .then() callback executed immediately before 'End'. However, promises are asynchronous and schedule microtasks that run after the current synchronous code completes. Therefore, 'End' logs before 'Success'.
C.
text
End
Start
Success
Incorrect. This incorrectly places 'End' before 'Start', but 'Start' is logged first because it appears first in the code. Synchronous code executes in order, so 'Start' always logs before 'End'.
D.
text
Success
Start
End
Incorrect. This places 'Success' before 'Start', but 'Success' is logged asynchronously after the synchronous code completes. The order is always synchronous code first, then microtasks.
Reference:
MDN Web Docs – Event loop and microtask queue
MDN Web Docs – Promise.resolve() and .then()
MDN Web Docs – Microtasks and task queue
Salesforce Trailhead – JavaScript Essentials: Asynchronous Programming and Event Loop
| Page 1 out of 30 Pages |