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
JavaScript:
01 function Tiger() {
02 this.type = ' Cat ' ;
03 this.size = ' large ' ;
04 }
05
06 let tony = new Tiger();
07 tony.roar = () = > {
08 console.log( ' They\ ' re great! ' );
09 };
10
11 function Lion() {
12 this.type = ' Cat ' ;
13 this.size = ' large ' ;
14 }
15
16 let leo = new Lion();
17 // Insert code here
18 leo.roar();
Which two statements could be inserted at line 17 to enable line 18?
A. leo.roar = () = > { console.log( ' They\ ' re pretty good! ' ); };
B. Object.assign(leo, tony);
C. Object.assign(leo, Tiger);
D. leo.prototype.roar = () = > { console.log( ' They\ ' re pretty good! ' ); };
B. Object.assign(leo, tony);
Explanation:
This question tests your understanding of object property assignment, prototypal inheritance, and the Object.assign() method in JavaScript. Line 18 calls leo.roar(), so the roar method must exist on leo itself or somewhere in its prototype chain before that line executes. The inserted code must ensure leo.roar is defined at the time of invocation.
Correct Options:
A. leo.roar = () => { console.log('They\'re pretty good!'); }; –
Correct. This directly adds a roar property to the leo object instance itself. Since leo is an instance of Lion, adding the method as an own property makes it immediately available. When line 18 executes, leo.roar() finds the method directly on the object and invokes it successfully.
B. Object.assign(leo, tony); –
Correct. The Object.assign() method copies all enumerable own properties from the source object (tony) to the target object (leo). Since tony has a roar method (added on line 07), this method gets copied to leo as an own property. When line 18 executes, leo.roar() exists and works correctly.
Incorrect Options:
C. Object.assign(leo, Tiger); –
Incorrect. Tiger is a constructor function, not an object instance. Object.assign() copies properties from the source object's own enumerable properties. The Tiger function has no roar property defined on it; the roar method exists only on the tony instance. Copying from Tiger would not add the roar method to leo.
D. leo.prototype.roar = () => { console.log('They\'re pretty good!'); }; –
Incorrect. leo is an object instance, not a constructor function. Instances do not have a prototype property; they have an internal [[Prototype]] (accessible via __proto__ or Object.getPrototypeOf()). Assigning to leo.prototype creates an own property named prototype on leo itself, which does not affect the method lookup for leo.roar(). The prototype property only exists on constructor functions, not on their instances.
Reference:
MDN Web Docs – Object.assign() method
MDN Web Docs – Working with objects and property assignment
MDN Web Docs – Inheritance and the prototype chain
Salesforce Trailhead – JavaScript Essentials: Objects and Prototypes
Refer to the code below:
01 x = 3.14;
02
03 function myFunction() {
04 ' use strict ' ;
05 y = x;
06 }
07
08 z = x;
09 myFunction();
Considering the implications of ' use strict ' on line 04, which three statements describe the execution of the code?
A. ' use strict ' is hoisted, so it has an effect on all lines.
B. z is equal to 3.14.
C. ' use strict ' has an effect between line 04 and the end of the file.
D. ' use strict ' has an effect only on line 05.
E. Line 05 throws an error.
D. ' use strict ' has an effect only on line 05.
E. Line 05 throws an error.
Explanation:
This question tests your understanding of strict mode in JavaScript, specifically how the 'use strict' directive works when placed inside a function. Strict mode is a directive that enables stricter parsing and error handling. When placed inside a function, it applies only to that function's scope and its nested functions. It does not affect code outside the function. In this code, x is assigned without a declaration on line 01 (creating an implicit global in non-strict mode). On line 05, y = x; is inside the function where strict mode is enabled, so assigning to an undeclared variable y throws a ReferenceError. On line 08, z = x; is outside the function, so it creates an implicit global z and is not affected by strict mode.
Correct Options:
B. z is equal to 3.14. –
Correct. Line 08 (z = x;) is outside the function and outside strict mode. Since x was assigned 3.14 on line 01 (creating an implicit global in non-strict mode), z is also assigned the value 3.14 as an implicit global. No error occurs because strict mode does not apply outside the function.
D. 'use strict' has an effect only on line 05. –
Correct. The 'use strict' directive is placed inside myFunction on line 04. It applies only to the scope of that function and its nested functions. It does not affect code outside the function (lines 01, 08, etc.). Therefore, its effect is limited to the lines inside the function, specifically line 05 where the error occurs.
E. Line 05 throws an error. –
Correct. Inside myFunction, strict mode is enabled. Line 05 attempts to assign a value to y without declaring it with var, let, or const. In strict mode, assigning to an undeclared variable throws a ReferenceError. This is the intended behavior of strict mode to prevent accidental global variable creation.
Incorrect Options:
A. 'use strict' is hoisted, so it has an effect on all lines. –
Incorrect. The 'use strict' directive is not hoisted to affect the entire file. It only applies to the function scope in which it is placed. It does not affect code outside the function (lines 01 and 08). Hoisting does not apply to directives in the same way it applies to variable declarations.
C. 'use strict' has an effect between line 04 and the end of the file. –
Incorrect. 'use strict' placed inside a function only affects that function's scope, not the entire file from line 04 onward. It does not affect lines outside the function, such as line 08. The scope of strict mode in this case is limited to myFunction.
Reference:
MDN Web Docs – Strict mode in JavaScript
MDN Web Docs – The 'use strict' directive and function scope
MDN Web Docs – Implicit globals and strict mode errors
Salesforce Trailhead – JavaScript Essentials: Strict Mode and Best Practices
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
Refer to the following code block:
01 let array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11];
02 let output = 0;
03
04 for (let num of array) {
05 if (output > 10) {
06 break;
07 }
08 if (num % 2 == 0) {
09 continue;
10 }
11 output += num;
12 }
What is the value of output after the code executes?
A. 16
B. 25
C. 11
D. 36
Explanation:
This question tests your understanding of loop control statements (break and continue) in JavaScript, specifically within a for...of loop. The code iterates through an array of numbers from 1 to 11. It adds only odd numbers to output (since even numbers are skipped using continue). The loop breaks immediately when output exceeds 10, stopping further iteration. The odd numbers are 1, 3, 5, 7, 9, 11... but the loop breaks after adding 9 because output becomes 16, which is > 10. The final value is 16.
Correct Option:
A. 16 – Correct. Let's trace the execution step by step:
output = 0
Iterate through array: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11
Incorrect Options:
B. 25 –
Incorrect. This would be the sum of all odd numbers from 1 to 9 (1+3+5+7+9 = 25) if the loop completed without breaking. However, the loop breaks when output > 10, which happens after adding 7 (output becomes 16). The loop does not continue to add 9, so 25 is incorrect.
C. 11 –
Incorrect. This is simply the value of the first odd number (1) plus the third odd number (3) plus the fifth odd number (5) plus the value 2? No clear pattern. This does not match the logic of the loop. The correct sum is 16, not 11.
D. 36 –
Incorrect. This would be the sum of all odd numbers from 1 to 11 (1+3+5+7+9+11 = 36) if the loop completed without breaking. However, the loop breaks early when output > 10, so it never reaches or adds 9 or 11. 36 is the sum of all odd numbers in the array, but the break condition prevents that.
Reference:
MDN Web Docs – for...of loop and iteration
MDN Web Docs – break statement
MDN Web Docs – continue statement
Salesforce Trailhead – JavaScript Essentials: Loops and Control Flow
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:
This question tests your understanding of EventEmitter-based APIs in Node.js and how to handle errors emitted as events. Server libraries built using events and callbacks typically extend the EventEmitter class and emit an 'error' event when issues occur during boot or runtime. To log errors at boot time, the developer must attach an event listener using .on() or .once() to listen for the 'error' event. The correct pattern is server.on('error', callback), which allows the callback to execute whenever an 'error' event is emitted.
Correct Option:
D. server.on('error', (error) => { console.log('ERROR', error); }); –
Correct. The server library is built using events and callbacks, meaning it extends EventEmitter and emits events like 'error'. The .on() method registers a listener for the 'error' event. When the server encounters an issue during boot, it emits the 'error' event, and the provided callback executes, logging the error. This is the standard and correct way to handle error events in Node.js EventEmitter-based libraries.
Incorrect Options:
A. server.error((error) => { console.log('ERROR', error); }); –
Incorrect. There is no .error() method on EventEmitter or on standard Node.js server objects. The correct method for listening to events is .on(), not .error(). This would throw a TypeError because server.error is undefined.
B. server.catch((error) => { console.log('ERROR', error); }); –
Incorrect. The .catch() method is used with Promises to handle rejections, not with EventEmitter-based libraries. Server libraries that use events and callbacks do not have a .catch() method. This would throw a TypeError because server.catch is undefined.
C. try { server.start(); } catch(error) { console.log('ERROR', error); } –
Incorrect. This uses synchronous try/catch to handle errors. However, the server library uses events and callbacks, meaning errors are emitted asynchronously via the 'error' event, not thrown synchronously. The try/catch block would not capture any asynchronous errors emitted during boot. This approach is only effective for synchronous code and would fail to log the error.
Reference:
Node.js Official Documentation – Events (EventEmitter)
Node.js Official Documentation – Error events and handling
MDN Web Docs – EventTarget and event listeners
Salesforce Trailhead – Node.js Development: Event-Driven Programming and Error Handling
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.