Last Updated On : 28-Sep-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.

147 Questions
Salesforce 2026

Given two expressions, exp1 and exp2, which two valid ways return the logical AND of the two expressions and ensure it is a Boolean?

A. Boolean(exp1 & & exp2)

B. Boolean(exp1) & & Boolean(exp2)

C. exp1 & exp2

D. Boolean(var1) & & Boolean(var2)

A.   Boolean(exp1 & & exp2)
B.   Boolean(exp1) & & Boolean(exp2)

Explanation:
This question tests your understanding of logical operations and type coercion in JavaScript, specifically how to ensure the result of a logical AND operation is a Boolean. The logical AND operator (&&) returns the first falsy operand or the last truthy operand, which may not always be a Boolean. To guarantee a Boolean result, you can either wrap the entire expression with Boolean() or explicitly convert each operand to Boolean using Boolean() before applying &&. Both approaches ensure the final result is a Boolean (true or false). The other options either use invalid syntax or refer to undefined variables.

Correct Options:

A. Boolean(exp1 && exp2) –
Correct. The expression exp1 && exp2 is evaluated first, and its result (which could be any truthy or falsy value) is then passed to Boolean(), which converts it to a strict Boolean (true or false). This guarantees that the final result is a Boolean.

B. Boolean(exp1) && Boolean(exp2) –
Correct. Each expression is individually converted to a Boolean using Boolean(), and then the && operator is applied. Since both operands are already Booleans, the result of && is also a Boolean (true if both are true, otherwise false). This ensures a Boolean result without relying on the original type of exp1 or exp2.

Incorrect Options:

C. exp1 & exp2 –
Incorrect. The & operator is the bitwise AND operator, not the logical AND. It operates on numbers by performing a bitwise comparison and returns a number, not a Boolean. This does not ensure a Boolean result and is not the logical AND operation.

D. Boolean(var1) && Boolean(var2) –
Incorrect. This option uses var1 and var2, but the question asks about exp1 and exp2. var1 and var2 are not defined in the context of the question, so this would throw a ReferenceError. Even if they were defined, the correct syntax would use exp1 and exp2.

Reference:

MDN Web Docs – Logical AND (&&) operator

MDN Web Docs – Boolean() constructor and type conversion

MDN Web Docs – Bitwise AND (&) operator

Salesforce Trailhead – JavaScript Essentials: Logical Operators and Type Coercion

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.)

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

Refer to the HTML below:

< div id= " main " >

< ul >

< li > Leo < /li >

< li > Tony < /li >

< li > Tiger < /li >

< /ul >

< /div >

Which JavaScript statement results in changing " Leo " to " The Lion " ?

A. document.querySelectorAll( ' #main #Leo ' ).innerHTML = ' The Lion ' ;

B. document.querySelector( ' #main li:second-child ' ).innerHTML = ' The Lion ' ;

C. document.querySelectorAll( ' #main li,Leo ' ).innerHTML = ' The Lion ' ;

D. document.querySelector( ' #main li:nth-child(1) ' ).innerHTML = ' The Lion ' ;

D.   document.querySelector( ' #main li:nth-child(1) ' ).innerHTML = ' The Lion ' ;

Explanation:
This question tests your knowledge of DOM selection methods and CSS selectors in JavaScript. The goal is to select the first

  • element (containing "Leo") and change its content to "The Lion". The correct approach is to use document.querySelector() with a valid CSS selector that targets the first child of the
      inside
      . The selector #main li:nth-child(1) correctly selects the first
    • element, and innerHTML updates its content. Other options either use invalid selectors, incorrect methods, or target the wrong element.

      Correct Option:

      D. document.querySelector('#main li:nth-child(1)').innerHTML = 'The Lion'; –
      Correct. The selector #main li:nth-child(1) selects the first
    • element that is a child of
        inside the element with ID main. Since "Leo" is in the first
      • , this correctly targets it. The innerHTML property then updates its content to 'The Lion'. This is a valid and precise way to select the first list item.

        Incorrect Options:

        A. document.querySelectorAll('#main #Leo').innerHTML = 'The Lion'; –
        Incorrect. There is no element with ID Leo; the text "Leo" is content, not an ID. querySelectorAll() returns a NodeList, which does not have a innerHTML property directly. This would throw a TypeError. Additionally, #Leo is not a valid selector for the text content.

        B. document.querySelector('#main li:second-child').innerHTML = 'The Lion'; –
        Incorrect. There is no :second-child pseudo-class in CSS. The correct pseudo-class is :nth-child(2) for the second child. This selector is invalid and would not match any element. This would return null and throw an error when trying to access innerHTML.

        C. document.querySelectorAll('#main li,Leo').innerHTML = 'The Lion'; –
        Incorrect. The selector #main li,Leo is invalid because Leo is not a valid selector (it would be interpreted as an element type, which does not exist). querySelectorAll() returns a NodeList, which does not have innerHTML. Even if the selector were valid, it would target multiple elements, and assigning innerHTML to a NodeList is not allowed.

        Reference:

        MDN Web Docs – Document.querySelector() method

        MDN Web Docs – CSS selectors (nth-child)

        MDN Web Docs – Element.innerHTML property

        Salesforce Trailhead – JavaScript Essentials: DOM Manipulation and Selectors
  • Given the code:

    01 function GameConsole(name) {

    02 this.name = name;

    03 }

    04

    05 GameConsole.prototype.load = function(gamename) {

    06 console.log( ' ${this.name} is loading a game: ${gamename}.... ' );

    07 }

    08

    09 function Console16bit(name) {

    10 GameConsole.call(this, name);

    11 }

    12

    13 Console16bit.prototype = Object.create(GameConsole.prototype);

    14

    15 // insert code here

    16 console.log( ' ${this.name} is loading a cartridge game: ${gamename}.... ' );

    17 }

    18

    19 const console16bit = new Console16bit( ' SNEGeneziz ' );

    20 console16bit.load( ' Super Monic 3x Force ' );

    What should a developer insert at line 15?

    A. Console16bit = Object.create(GameConsole.prototype).load = function(gamename) {

    B. Console16bit.prototype.load(gamename) = function() {

    C. Console16bit.prototype.load(gamename) {

    D. Console16bit.prototype.load = function(gamename) {

    D.   Console16bit.prototype.load = function(gamename) {

    Explanation:
    This question tests your understanding of prototypal inheritance and method overriding in JavaScript. The Console16bit class inherits from GameConsole. To override the load method for Console16bit instances, you need to assign a new function to Console16bit.prototype.load. This method will be called instead of the parent's load method when invoked on a Console16bit instance. The correct syntax is Console16bit.prototype.load = function(gamename) { ... }. This ensures that the child class has its own version of the load method, and the super call is not needed in this case.

    Correct Option:

    D. Console16bit.prototype.load = function(gamename) { –
    Correct. This assigns a new function to the load property on Console16bit.prototype, overriding the inherited method from GameConsole.prototype. When console16bit.load('Super Monic 3x Force') is called, the overridden method executes, logging the cartridge game message. This is the correct way to override a prototype method in JavaScript.

    Incorrect Options:

    A. Console16bit = Object.create(GameConsole.prototype).load = function(gamename) { –
    Incorrect. This syntax is invalid and attempts to reassign Console16bit (the constructor function) to the result of Object.create(GameConsole.prototype).load. This would overwrite the constructor and break the prototype chain. It does not correctly override the load method on the prototype.

    B. Console16bit.prototype.load(gamename) = function() { –
    Incorrect. This syntax is invalid in JavaScript. You cannot assign a function to a method call like Console16bit.prototype.load(gamename). The correct approach is to assign a function directly to the property Console16bit.prototype.load.

    C. Console16bit.prototype.load(gamename) { –
    Incorrect. This syntax is invalid. Method definitions inside classes use methodName() { ... }, but when working with prototypes directly, you must assign a function to the prototype property. The correct syntax is Console16bit.prototype.load = function(gamename) { ... }.

    Reference:

    MDN Web Docs – Prototype-based inheritance and method overriding

    MDN Web Docs – Function.prototype and prototype property

    MDN Web Docs – Object.create() for inheritance

    Salesforce Trailhead – JavaScript Essentials: Object-Oriented Programming 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.

    B.   z is equal to 3.14.
    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

    Salesforce-JavaScript-Developer Exam Questions - Home Previous
    Page 4 out of 30 Pages