Salesforce Certified JavaScript Developer I Free Sample Questions

Description

Covers JavaScript variables, types and collections, objects, functions and classes, browser events and the DOM, debugging, asynchronous programming, Node.js, and unit testing.

17 free sample questions204 in the full practice test

Try simulator

JS-Dev-101 Sample Questions

  1. Question 1

    Intermediate

    Variables, Types, and Collections · Array Data Manipulation

    A developer is building a financial dashboard that processes transaction lists. They need to calculate the total balance from an array of transaction objects, where each object contains a type ('credit' or 'debit') and an amount.

    Which array method and implementation best achieves this single-value result?

    Answer and explanation

    Correct answer: C

    The reduce() method is specifically designed to transform an array into a single value (the accumulator) by applying a function to each element. map() creates a new array of the same length, which is not the goal here.

  2. Question 2

    Beginner

    Variables, Types, and Collections · Variables and Initialization

    A developer encounters a bug where a variable declared inside a for loop is accessible outside the loop, causing unexpected behavior in subsequent logic. The code uses the var keyword.

    Which explanation describes why this is happening?

    Answer and explanation

    Correct answer: C

    The var keyword creates variables that are function-scoped (or globally scoped if outside a function). They ignore block boundaries like if statements or for loops. To restrict the variable to the loop block, let should be used.

  3. Question 3

    Intermediate

    Variables, Types, and Collections · Array Data Manipulation

    A developer needs to create a unique list of user IDs from a raw array that contains duplicates. The final result must be an array.

    Which approach provides the most concise and performant solution?

    Answer and explanation

    Correct answer: A

    The Set object stores only unique values. Passing the array to the Set constructor removes duplicates, and the spread syntax [...] converts it back to an array. This is more concise and generally more performant (O(n)) than using filter with indexOf (O(n^2)).

  4. Question 4

    Beginner

    Variables, Types, and Collections · Variables and Initialization

    Consider the following code snippet involving object mutation:

    const config = {
    env: 'dev',
    retries: 3
    };
    config.retries = 5;
    config = { env: 'prod', retries: 1 };
    

    What happens when this code executes?

    Answer and explanation

    Correct answer: B

    The const keyword prevents reassignment of the variable identifier itself. However, if the variable holds an object, the contents of that object (its properties) can still be modified. Therefore, config.retries = 5 succeeds, but config = {...} throws a TypeError.

  5. Question 5

    Intermediate

    Variables, Types, and Collections · Array Data Manipulation

    A developer needs to sort an array of product objects by price (ascending). The price is a numeric property.

    const products = [{id: 1, price: 100}, {id: 2, price: 5}, {id: 3, price: 25}];

    Which sort implementation works correctly?

    Answer and explanation

    Correct answer: D

    The sort method expects the comparison function to return a negative number, zero, or a positive number. a.price - b.price correctly returns a negative value if a is smaller than b, sorting them in ascending order.

  6. Question 6

    Advanced

    Variables, Types, and Collections · JSON Operations

    A developer is parsing a JSON string received from an API. The string contains a date field in ISO format. The developer wants to automatically convert this string into a JavaScript Date object during parsing.

    Which feature of JSON.parse should be used?

    Answer and explanation

    Correct answer: B

    JSON.parse() accepts a second argument called the 'reviver' function. This function is called for each key-value pair and can be used to transform values (like converting an ISO date string into a Date object) before the final object is returned.

  7. Question 7

    IntermediateMultiple answers

    Variables, Types, and Collections · Type Coercion

    Which of the following expressions evaluates to true in JavaScript? (Select TWO)

    Answer and explanation

    Correct answers: C, D

    null == undefined is true because they are loosely equal. [] (empty array) is a truthy value, so !![] is true.

    Objects (including arrays) are always truthy in JavaScript.

  8. Question 8

    Beginner

    Variables, Types, and Collections · Variables and Initialization

    A developer writes the following function to create a greeting:

    function greet(name, greeting = 'Hello') {
    return `${greeting}, ${name}!`;
    }
    

    What feature is being used for the greeting argument?

    Answer and explanation

    Correct answer: C

    The syntax greeting = 'Hello' defines a default parameter. If the caller does not provide a value for greeting (or passes undefined), the function uses 'Hello'.

Register free for 9 more questions

Or unlock all 204 JS-Dev-101 questions with explanations, timed mode and flashcards.