Last Updated On : 29-Jun-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
A developer creates a new web server that uses Node.js. It imports a server library that uses events and callbacks for handling server functionality. The server library is imported with require and is made available to the code by a variable named server. The developer wants to log any issues that the server has while booting up.
Which code logs an error at boot time with an event?
A. server.error((error) = > {
console.log( ' ERROR ' , error);
});
B. server.catch((error) = > {
console.log( ' ERROR ' , error);
});
C. try {
server.start();{
} catch(error) {{
console.log( ' ERROR ' , error);{
}
D. server.on( ' error ' , (error) = > {
console.log( ' ERROR ' , error);
});
console.log( ' ERROR ' , error);
});
Explanation:
Event emitters in Node.js (such as a server library) use the .on() method to register event listeners. The 'error' event is a standard event that many Node.js core modules emit when an error occurs. To log issues during server boot, the developer attaches a listener for the 'error' event using .on('error', callback).
Correct Option:
D: server.on('error', (error) => { console.log('ERROR', error); });
The .on() method registers an event listener for the specified event name. When the server emits an 'error' event during boot (or at any time), the provided callback executes, logging the error. This is the standard Node.js event handling pattern.
Incorrect Option:
A: server.error((error) => { console.log('ERROR', error); });
.error() is not a standard method for event handling in Node.js. Event emitters use .on() or .addListener(), not .error(). This would throw a TypeError.
B: server.catch((error) => { console.log('ERROR', error); });
.catch() is used with Promises, not with event emitters. The server library uses events and callbacks (as stated), not Promises. This method does not exist on the server object and would cause an error.
C: try { server.start(); } catch(error) { console.log('ERROR', error); }
The try-catch block only handles synchronous errors that are thrown directly. If the server emits an error asynchronously via an event (which is typical for Node.js server boot issues), try-catch will not catch it because the error occurs after the synchronous code has completed.
Reference:
Node.js Documentation – "Event Emitter": The EventEmitter class provides .on(eventName, listener) to register listeners for specific events. The 'error' event is special; if emitted and no listener is registered, the Node.js process may print the error and exit. Always attach an 'error' listener to prevent crashes.
Which statement allows a developer to update the browser navigation history without a page refresh?
A. window.customHistory.pushState(newStateObject, ' ' , null);
B. window.history.createState(newStateObject, ' ' );
C. window.history.pushState(newStateObject, ' ' , null);
D. window.history.updateState(newStateObject, ' ' );
Explanation:
The HTML5 History API provides window.history.pushState() to add a new entry to the browser's session history stack. This method changes the URL displayed in the address bar without causing a page refresh, enabling single-page applications (SPAs) to manage navigation seamlessly.
Correct Option:
C: window.history.pushState(newStateObject, ' ', null);
pushState() takes three parameters: a state object, a title (ignored but often passed as empty string), and an optional URL. When executed, it adds a new history entry and updates the browser's URL without reloading the page. This allows the developer to control navigation flow programmatically.
Incorrect Option:
A: window.customHistory.pushState(newStateObject, ' ', null);
customHistory is not a standard browser API object. The correct object is window.history. There is no customHistory property on the window object in standard JavaScript.
B: window.history.createState(newStateObject, ' ');
createState() is not a valid method of the History API. The correct methods are pushState(), replaceState(), back(), forward(), and go(). createState does not exist.
D: window.history.updateState(newStateObject, ' ');
updateState() is not a standard method of the History API. To modify the current history entry without adding a new one, developers use replaceState(), not updateState().
Reference:
MDN Web Docs – "History.pushState()": The pushState() method adds a new entry to the session history stack without refreshing the page. The syntax is history.pushState(state, title, url). This is the standard API for client-side navigation in single-page applications.
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(true);
console.assert(res === ' ' );
B. let res = fizzbuzz(3);
console.assert(res === ' ' );
C. let res = fizzbuzz(5);
console.assert(res === ' fizz ' );
D. let res = fizzbuzz(15);
console.assert(res === ' fizzbuzz ' );
console.assert(res === ' ' );
D. let res = fizzbuzz(15);
console.assert(res === ' fizzbuzz ' );
Explanation:
Proper test cases for the fizzbuzz function must pass numeric inputs and verify the correct string output based on divisibility rules. Edge cases like non‑numeric inputs (e.g., true) are also valid to test function robustness. Option A tests a truthy non‑number (coerced to 1, not divisible by 3 or 5 → empty string). Option D tests divisibility by both 3 and 5.
Correct Option:
A: let res = fizzbuzz(true); console.assert(res === '');
In JavaScript, true coerces to 1 when used in numeric operations. 1 is divisible by neither 3 nor 5, so the function should return an empty string ''. This tests how the function handles non‑numeric truthy input.
D: let res = fizzbuzz(15); console.assert(res === 'fizzbuzz');
15 is divisible by both 3 and 5, so the function must return 'fizzbuzz'. This tests the combined condition, which is the most specific rule and should take precedence over individual 'fizz' or 'buzz'.
Incorrect Option:
B: let res = fizzbuzz(3); console.assert(res === '');
3 is divisible by 3, so the function should return 'fizz', not an empty string. The assertion expects '', which is incorrect for this input. This test would fail.
C: let res = fizzbuzz(5); console.assert(res === 'fizz');
5 is divisible by 5, so the function should return 'buzz', not 'fizz'. The assertion expects 'fizz', which is incorrect for this input. This test would fail.
Reference:
MDN Web Docs – "console.assert()": Used for testing conditions. If the condition is false, an error is logged.
Testing best practices: Test typical cases (3, 5, 15) and edge cases (non‑numbers, negative numbers, zero). For fizzbuzz(15), ensure the 'fizzbuzz' condition is checked before 'fizz' or 'buzz' to avoid premature matches.
let sampleText = " The quick brown fox jumps " ;
Which three expressions return true for a substring?
A. sampleText.includes( ' fox ' );
B. sampleText.indexOf( ' quick ' ) > -1;
C. sampleText.indexOf( ' fox ' ) !== -1;
D. sampleText.include( ' fox ' ) !== -1;
E. sampleText.indexOf( ' Quick ' ) !== -1;
B. sampleText.indexOf( ' quick ' ) > -1;
C. sampleText.indexOf( ' fox ' ) !== -1;
Explanation:
Checking for a substring means determining whether a specific sequence of characters exists within a string. The includes() method returns a boolean (true/false). The indexOf() method returns the starting index of the substring or -1 if not found. A return value greater than -1 indicates the substring exists.
Correct Option:
A: sampleText.includes('fox');
includes() directly returns true if the substring is found anywhere in the string. The string "The quick brown fox jumps" contains "fox", so this returns true.
B: sampleText.indexOf('quick') > -1;
indexOf('quick') returns the index of "quick" (which is 4). Since 4 > -1 evaluates to true, this correctly indicates the substring exists.
C: sampleText.indexOf('fox') !== -1;
indexOf('fox') returns the index of "fox" (which is 16). Since 16 !== -1 evaluates to true, this correctly indicates the substring exists.
Incorrect Option:
D: sampleText.include('fox') !== -1;
include() is not a standard JavaScript method (the correct method is includes). This will throw a TypeError. Even if corrected, includes() returns a boolean, not a number, so comparing it to -1 is illogical.
E: sampleText.indexOf('Quick') !== -1;
indexOf() is case-sensitive. The string contains "quick" (lowercase q), not "Quick" (uppercase Q). This returns -1, so -1 !== -1 evaluates to false.
Reference:
MDN Web Docs – "String.prototype.includes()": Returns true if the substring is found; otherwise false.
MDN Web Docs – "String.prototype.indexOf()": Returns the index of the first occurrence, or -1 if not found. To check existence, compare the return value to -1. Both methods are case-sensitive.
for (let number = 2; number < = 5; number += 1) {
// faster code statement here
}
Which statement meets the requirements to log an error when the Boolean statement evaluates to false?
A. console.classy(number + 2 === 0);
B. assert(number + 2 === 0);
C. console.assert(number + 2 === 0);
D. console.error(number + 2 === 0);
Explanation:
The requirement is to log an error when a Boolean statement evaluates to false. console.assert() is specifically designed for this purpose. It takes a condition as its first argument; if the condition is false, it logs an error message to the console without throwing an exception or breaking execution.
Correct Option:
C: console.assert(number + 2 === 0);
console.assert(condition, message) evaluates the condition. When condition is false, it logs an error to the console. In the loop, number + 2 === 0 is always false (since number ranges from 2 to 5, so number+2 is 4 to 7). Thus, an assertion error will be logged on each iteration.
Incorrect Option:
A: console.classy(number + 2 === 0);
console.classy is not a standard JavaScript method. This will throw a TypeError and is not valid for logging errors.
B: assert(number + 2 === 0);
assert() is not a global function in standard browser JavaScript. It exists in Node.js (require('assert')) but not in browser console environments. This would throw a ReferenceError.
D: console.error(number + 2 === 0);
console.error() always logs an error, regardless of the condition. It does not evaluate the Boolean to determine whether to log; it logs the Boolean value itself (true or false). This does not meet the requirement of logging an error only when the condition is false.
Reference:
MDN Web Docs – "console.assert()": The console.assert() method writes an error message to the console if the specified assertion is false. If the assertion is true, nothing happens. This is ideal for conditional logging during development and testing.
| Salesforce-JavaScript-Developer Exam Questions - Home | Previous |
| Page 7 out of 55 Pages |