Salesforce-JavaScript-Developer Exam Questions With Explanations
The best Salesforce-JavaScript-Developer practice exam questions with research based explanations of each question will help you Prepare & Pass the exam!
Over 15K Students have given a five star review to SalesforceKing
Why choose our Practice Test
By familiarizing yourself with the Salesforce-JavaScript-Developer exam format and question types, you can reduce test-day anxiety and improve your overall performance.
Up-to-date Content
Ensure you're studying with the latest exam objectives and content.
Unlimited Retakes
We offer unlimited retakes, ensuring you'll prepare each questions properly.
Realistic Exam Questions
Experience exam-like questions designed to mirror the actual Salesforce-JavaScript-Developer test.
Targeted Learning
Detailed explanations help you understand the reasoning behind correct and incorrect answers.
Increased Confidence
The more you practice, the more confident you will become in your knowledge to pass the exam.
Study whenever you want, from any place in the world.
Salesforce Salesforce-JavaScript-Developer Exam Sample Questions 2026
Start practicing today and take the fast track to becoming Salesforce Salesforce-JavaScript-Developer certified.
21474 already prepared
Salesforce 2026 Release147 Questions
4.9/5.0
Which two implementations of utils.js support foo and bar?
A. const foo = () = > { return ' foo ' ; };
const bar = () = > { return ' bar ' ; };
export { foo, bar };
B. const foo = () = > { return ' foo ' ; };
const bar = () = > { return ' bar ' ; };
export default { foo, bar };
C. import { foo, bar } from " ./helpers/utils.js " ;
export { foo, bar };
D. export default class {
foo() { return ' foo ' ; }
bar() { return ' bar ' ; }
}
const bar = () = > { return ' bar ' ; };
export { foo, bar };
C. import { foo, bar } from " ./helpers/utils.js " ;
export { foo, bar };
Explanation:
This question tests your understanding of ES6 module export syntax, specifically named exports versus default exports. The question asks which implementations of utils.js support foo and bar, implying that these functions must be available as named exports that can be imported elsewhere. Named exports and re-exports are the correct approaches for supporting individual function exports.
Correct Options:
A. const foo = () => { return ' foo '; }; const bar = () => { return ' bar '; }; export { foo, bar }; –
Correct. This uses named exports with the export keyword and an export list. Both foo and bar are exported individually as named exports. This allows other modules to import them using import { foo, bar } from './utils.js'. This is the standard way to export multiple named functions from a module.
C. import { foo, bar } from "./helpers/utils.js"; export { foo, bar }; –
Correct. This demonstrates re-exporting named exports. The code imports foo and bar from another file and immediately re-exports them using export { foo, bar }. This pattern is commonly used in index files to aggregate exports from multiple modules. As long as foo and bar are available in the imported file, this implementation supports them as named exports.
Incorrect Options:
B. const foo = () => { return ' foo '; }; const bar = () => { return ' bar '; }; export default { foo, bar }; –
Incorrect. This exports a single default export containing an object with foo and bar as properties. While foo and bar are accessible, they are not named exports. Importers would need to use import utils from './utils.js' and then access utils.foo and utils.bar. The question asks for implementations that support foo and bar as individual exports, which this does not.
D. export default class { foo() { return ' foo '; } bar() { return ' bar '; } } –
Incorrect. Similar to option B, this exports a single default export, which is a class containing foo and bar as methods. These are not named exports. To use them, the importer would need to instantiate the class or access static methods. This does not support foo and bar as standalone named exports.
Reference:
MDN Web Docs – export statement (named exports and re-exports)
MDN Web Docs – import statement
MDN Web Docs – export default vs named exports
Salesforce Trailhead – Lightning Web Components: JavaScript Modules and ES6 Imports
A developer uses a parsed JSON string to work with user information as in the block below:
01 const userInformation = {
02 " id " : " user-01 " ,
03 " email " : " user01@universalcontainers.demo " ,
04 " age " : 25
05 };
Which two options access the email attribute in the object?
A. userInformation.email
B. userInformation.get( " email " )
C. userInformation[ " email " ]
D. userInformation[email]
C. userInformation[ " email " ]
Explanation:
This question tests your understanding of accessing object properties in JavaScript. There are two primary ways to access properties of an object: dot notation (object.property) and bracket notation (object["property"]). Dot notation is simpler and more readable when the property name is a valid identifier. Bracket notation is useful when the property name is a string variable, contains special characters, or is a dynamic key. In this case, the email property can be accessed using userInformation.email or userInformation["email"].
Correct Options:
A. userInformation.email –
Correct. Dot notation is the standard and most common way to access object properties. Since email is a valid identifier (no spaces or special characters), userInformation.email correctly returns the value "user01@universalcontainers.demo".
C. userInformation["email"] –
Correct. Bracket notation allows you to access properties using a string key. userInformation["email"] correctly returns the value of the email property. This is especially useful when the property name is dynamic or contains characters that are not allowed in dot notation.
Incorrect Options:
B. userInformation.get("email") –
Incorrect. There is no get() method on plain JavaScript objects. This syntax is not valid for accessing properties. It would throw a TypeError because userInformation.get is undefined.
D. userInformation[email] –
Incorrect. This uses bracket notation but without quotes around email. JavaScript treats email as a variable name, not as a string literal. Unless there is a variable named email defined elsewhere, this will throw a ReferenceError. To access the email property, you need to use "email" (a string) inside the brackets.
Reference:
MDN Web Docs – Property accessors (dot notation and bracket notation)
MDN Web Docs – Working with objects
MDN Web Docs – JavaScript object basics
Salesforce Trailhead – JavaScript Essentials: Objects and Property Access
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 code below:
01 const myFunction = arr = > {
02 return arr.reduce((result, current) = > {
03 return result + current;
04 }, 10);
05 }
What is the output of this function when called with an empty array?
A. Returns 0
B. Throws an error
C. Returns NaN
D. Returns 5 # (Text here appears to be a typo; correct value is 10, see explanation.)
Explanation:
This question tests your understanding of the Array.prototype.reduce() method and its initial value parameter. The reduce() method executes a reducer function on each element of the array, resulting in a single output value. The second argument to reduce() is the initial value for the accumulator. In this code, the initial value is 10. When the array is empty, reduce() returns the initial value without ever calling the reducer function. Therefore, calling myFunction([]) returns 10, not 0, NaN, or an error.
Correct Option:
D. Returns 10 –
Correct. The reduce() method is called with an initial value of 10 (the second argument). When the array is empty, the reducer function is never called, and reduce() simply returns the initial value, which is 10. This is the expected behavior of reduce() with an initial value.
Incorrect Options:
A. Returns 0 –
Incorrect. This would be the result if the initial value were 0 or if the array were not empty and the sum of all elements was 0. However, the initial value is 10, and since the array is empty, the result is 10, not 0.
B. Throws an error –
Incorrect. reduce() only throws an error when called on an empty array without an initial value. Since an initial value (10) is provided, no error is thrown. The function executes successfully and returns the initial value.
C. Returns NaN –
Incorrect. NaN would result if the reducer function performed an invalid numeric operation on non-numeric values. However, since the array is empty, the reducer function is never invoked, and the initial value 10 is returned directly. No numeric operation occurs.
Reference:
MDN Web Docs – Array.prototype.reduce() method
MDN Web Docs – reduce() with initial value
MDN Web Docs – reduce() on empty arrays
Salesforce Trailhead – JavaScript Essentials: Arrays and Array Methods
Original constructor function:
01 function Vehicle(name, price) {
02 this.name = name;
03 this.price = price;
04 }
05 Vehicle.prototype.priceInfo = function () {
06 return `Cost of the $(this.name) is $(this.price)$`;
07 }
08 var ford = new Vehicle( ' Ford Fiesta ' , ' 20,000 ' );
Which class definition is correct?
A. class Vehicle {
constructor(name, price) {
this.name = name;
this.price = price;
}
priceInfo() {
return ' Cost of the ${this.name} is ${this.price}$ ' ;
}
}
B. class Vehicle {
vehicle(name, price) {
this.name = name;
this.price = price;
}
priceInfo() {
return ' Cost of the ${this.name} is ${this.price}$ ' ;
}
}
C. class Vehicle {
constructor() {
this.name = name;
this.price = price;
}
priceInfo() {
return `Cost of the ${this.name} is ${this.price}$`;
}
}
D. class Vehicle {
constructor(name, price) {
this.name = name;
this.price = price;
}
priceInfo() {
return `Cost of the ${this.name} is ${this.price}$`;
}
}
constructor(name, price) {
this.name = name;
this.price = price;
}
priceInfo() {
return `Cost of the ${this.name} is ${this.price}$`;
}
}
Explanation:
This question tests your understanding of converting a constructor function and prototype method into an ES6 class definition. In a class, the constructor method is used to initialize instance properties with the parameters passed during instantiation. The method priceInfo is defined as a class method, which is placed on the class's prototype (equivalent to the original prototype assignment). The template literal syntax requires backticks (`) for string interpolation with ${}, not single quotes ('). Option D correctly uses the constructor with parameters and a properly formatted template literal method.
Correct Option:
D.
javascript
class Vehicle {
constructor(name, price) {
this.name = name;
this.price = price;
}
priceInfo() {
return `Cost of the ${this.name} is ${this.price}$`;
}
}
This is correct. The constructor receives name and price parameters and assigns them to this. The priceInfo method is defined as a class method (on the prototype) and correctly uses a template literal with backticks to interpolate this.name and this.price. This accurately replicates the original constructor and prototype method.
Incorrect Options:
A. –
Incorrect. This option uses single quotes (') for the string in priceInfo, which treats ${this.name} and ${this.price} as literal text rather than interpolated expressions. The result would be the literal string "Cost of the ${this.name} is ${this.price}$", not the interpolated values. Template literals require backticks.
B. –
Incorrect. This option uses a method named vehicle instead of the required constructor. In ES6 classes, instance initialization must happen in the constructor method. The vehicle method would not be called automatically when new Vehicle() is invoked, so this.name and this.price would remain undefined. Additionally, it uses single quotes instead of backticks.
C. –
Incorrect. This option defines a constructor with no parameters, but then attempts to assign name and price to this using undefined variables. When new Vehicle('Ford Fiesta', '20,000') is called, name and price are not defined in the constructor's scope, so this.name and this.price would be undefined. The method correctly uses backticks, but the constructor is wrong.
Reference:
MDN Web Docs – Class constructor and method definitions
MDN Web Docs – Template literals (backticks)
MDN Web Docs – Classes and inheritance
Salesforce Trailhead – JavaScript Essentials: Object-Oriented Programming and Classes
Prep Smart, Pass Easy Your Success Starts Here!
Transform Your Test Prep with Realistic Salesforce-JavaScript-Developer Exam Questions That Build Confidence and Drive Success!
Salesforce JavaScript Developer I – Frequently Asked Questions
- Core JavaScript: variables, functions, scope, objects, arrays
- Asynchronous patterns: promises,
async/await - Browser & events: propagation, default behavior
- Error handling & debugging
- Testing with Jest
- LWC fundamentals: decorators, events, data access
async/await. You should handle rejections cleanly and avoid callback hell.import/export usage. Try realistic code challenges.
fetch, and common Web APIs.@salesforce/sfdx-lwc-jest, mock Apex and wire adapters, flush promises for async, and assert both DOM changes and events.