Limited-Time Offer: Enjoy 50% Savings! Coupon code: 50OFF Use it at checkout
Skip to content

Free Salesforce Certified JavaScript Developer JS-Dev-101 Exam Questions

Last updated: · 11 practice questions with answers and explanations

Page: 1 / 15 Total 147 questions

Want more questions? Get Premium Access.

Question 1

New Single answer

Topic: Variables, types, and collections

Skill tested: Selects Map and Set structures to preserve key identity and enforce unique values.

A JavaScript service processes product records from an upstream system. Each record has an object-valued `product` reference and a list of related category names. The service must look up metadata by the exact product object reference and produce a de-duplicated list of category names while preserving their first-seen order. Product references must not be converted to strings, and the implementation should use standard JavaScript collections. Which design satisfies both requirements?

Correct Answer: B. Use a `Map` keyed by each product object and a `Set` populated with category names in encounter order.
Explanation:

A `Map` accepts object keys and compares them by object identity, so it can distinguish the exact product references without string conversion. A `Set` stores unique values and iterates in insertion order, preserving the first-seen order of category names. A plain object with stringified keys can collapse distinct references and sorting changes encounter order. A `WeakMap` is not iterable, so it does not suit general collection processing, while a `WeakSet` accepts only objects and cannot store category strings.

Question 2

New Single answer

Topic: Variables, types, and collections

Skill tested: Applies block scope and per-iteration bindings when creating asynchronous callbacks.

A browser-based reporting tool creates one button for each report and attaches a click handler inside a loop. Each handler must display the report name associated with its own button when clicked later. The application uses modern JavaScript, and the team wants a simple implementation that does not introduce a helper function or change the event model. Which loop declaration best meets the requirement?

Correct Answer: C. Declare the loop counter with `let` in the loop initializer and capture the per-iteration report name.
Explanation:

A `let` declaration in a loop initializer creates a distinct binding for each iteration, so a callback closes over the report name for the button created during that iteration. With `var`, handlers share the same function-scoped binding and commonly observe the final loop value unless extra capture logic is added. `const` cannot be incremented by the loop update expression. The event handler's `this` does not inherently identify the report name unless the application explicitly stores and retrieves that data.

Question 3

New Multiple answers

Topic: Variables, types, and collections

Skill tested: Chooses safe type checks and optional access for values that may be absent or nonnumeric.

A JavaScript integration receives a `quantity` field from an external payload. The field may be absent, `null`, a numeric string, a number, or another value. The business rule accepts only finite JavaScript numbers, including zero, and must reject numeric strings rather than coerce them. The integration should not throw when the field is missing. Which two implementations meet the rule? Select TWO.

Correct Answer: B. Use `typeof payload.quantity === 'number' && Number.isFinite(payload.quantity)`.; C. Use `Number.isFinite(payload?.quantity)`.
Explanation:

Both A and D require the value itself to be a finite number; `Number.isFinite` does not coerce numeric strings, and optional chaining makes D safe when `payload` is nullish. A also works when `payload` is an object with an absent field because `typeof undefined` is not `number`. B coerces strings such as `"12"` to numbers, contrary to the rule. C accepts values that are not numbers, and E conflates valid zero with missing or other falsy values while also supplying a default the business rule did not request.

Question 4

New Single answer

Topic: Objects, functions, and classes

Skill tested: Uses lexical arrow-function binding and method syntax appropriately for object behavior.

A client-side telemetry module stores an object with a `send` method and a `schedule` method. `schedule` passes a callback to a timer; when the callback runs, it must call `send` on the telemetry object. The callback does not need its own dynamic `this`, and the methods should remain easy to read and maintain. Which implementation is most appropriate?

Correct Answer: A. Define `schedule` as a method and use an arrow callback that calls `this.send()`.
Explanation:

A concise method definition gives `schedule` its receiver when invoked as `telemetry.schedule()`. The nested arrow callback captures that lexical `this`, so it calls `send` on the telemetry object when the timer invokes it later. Passing `this.send` directly can lose its receiver, since timers do not generally bind callbacks to the originating object. A normal callback has its own call-site-dependent `this`, and making `schedule` an arrow property also changes how its receiver is determined.

Question 5

New Single answer

Topic: Objects, functions, and classes

Skill tested: Uses ES module exports and imports to organize code and control module scope.

A team is extracting a reusable date-formatting utility from a browser application into an ES module. The module has one primary formatter and two named helper functions. The application should import the primary formatter under a local alias and import only one helper; the other helper should remain private to the module. Which approach supports these requirements?

Correct Answer: A. Use a default export for the formatter, named exports for the required helper, and do not export the private helper.
Explanation:

An ES module can have one default export and any number of named exports. The consumer can alias a default import with its local binding name and import the required named helper, while an unexported function stays inaccessible to importers. A can work for aliasing a named export but does not satisfy the requirement that the formatter be the primary default export and exposes the extra helper. ES modules do not allow multiple default exports, and using a global object abandons module encapsulation.

Question 6

New Multiple answers

Topic: Objects, functions, and classes

Skill tested: Designs class inheritance and method overriding while preserving reusable base behavior.

A logistics application models `Shipment` objects with a shared tracking identifier and a `status()` method. `ExpressShipment` and `FreightShipment` need specialized status text, but both should retain the inherited identifier and be usable anywhere a `Shipment` is expected. The team wants conventional JavaScript class inheritance and does not want to duplicate the base initialization. Which two design choices meet the requirements? Select TWO.

Correct Answer: A. Override `status()` in each subclass while keeping a compatible method contract.; D. Declare each specialized class with `extends Shipment` and call `super(trackingId)` from its constructor.
Explanation:

`extends` establishes the prototype inheritance relationship, and `super(trackingId)` invokes the base constructor so the shared identifier initialization is not duplicated. Each subclass can override `status()` while preserving the expected behavior and interface for consumers that accept a `Shipment`. Copying assignments does not establish the subtype relationship. JavaScript class inheritance is single-chain, so a base class cannot extend both subclasses; unrelated objects also do not become instances of `Shipment` merely by having similar properties.

Question 7

New Single answer

Topic: Browsers and events

Skill tested: Controls event propagation and default browser actions for delegated DOM handlers.

A single-page application renders a table whose rows are replaced whenever data refreshes. Each row contains a link that opens a record in the application, but clicking the link must not navigate the browser away from the page. To avoid attaching listeners to every newly rendered link, the developer plans to handle clicks on the table element. Which implementation is most appropriate?

Correct Answer: C. Attach a click listener to the table, identify the clicked link from the event target or its closest matching ancestor, and call `preventDefault()`.
Explanation:

Event bubbling lets a listener on the stable table handle clicks originating from links inserted later. The handler should identify the relevant link - using `closest()` where appropriate - and call `preventDefault()` to cancel the link's browser navigation while performing the application's action. `stopPropagation()` only affects propagation and does not cancel a default action. Reattaching listeners to each link is brittle across replacement, and suppressing every click with `stopImmediatePropagation()` would interfere with unrelated handlers.

Question 8

New Single answer

Topic: Debugging and error handling

Skill tested: Uses try, catch, and finally to handle failures while guaranteeing cleanup.

A JavaScript data-import routine acquires a temporary lock, parses an uploaded document, and then writes validated records. Parsing or writing can fail, and callers need the original error information for diagnostics. Regardless of success or failure, the routine must release the lock. Which control-flow approach best meets these requirements?

Correct Answer: C. Place lock release in a `finally` block and either rethrow the caught error or let it propagate after any necessary context is added.
Explanation:

A `finally` block runs after the `try` and any matching `catch` complete, including when parsing or writing throws, making it the appropriate place for unconditional lock release. The routine can preserve diagnostic value by allowing the original exception to propagate or by rethrowing it after adding meaningful context. Returning an empty result hides failure, and cleanup after the try block may be skipped by an exception. A `finally` block does run on error; returning from it can also override earlier returns or thrown errors.

Question 9

New Multiple answers

Topic: Asynchronous programming

Skill tested: Coordinates independent Promises concurrently and handles aggregate failures explicitly.

A dashboard needs three independent API responses before it can render a summary. The requests do not depend on one another, and the dashboard should display the summary only if all three succeed. If any request fails, the caller should receive the failure rather than render a partial summary. The requests should start without waiting for earlier requests to finish. Which two approaches satisfy these requirements? Select TWO.

Correct Answer: B. Call each request to obtain a Promise, pass the Promises to `Promise.all`, and render using the resulting values.; E. Start all three requests and use `Promise.all` inside an `async` function, allowing rejection to propagate or catching and rethrowing it.
Explanation:

`Promise.all` receives already-started Promises, so independent requests can proceed concurrently. It fulfills with values in input order only when all Promises fulfill, and rejects when a constituent Promise rejects; this matches the all-or-failure rendering rule. D expresses the same behavior with `async`/`await` and preserves failure through propagation or rethrowing. Sequential awaits delay later starts. `Promise.allSettled` and independent callbacks encourage partial results, which violate the stated requirement.

Question 10

New Single answer

Topic: Server-side JavaScript

Skill tested: Distinguishes server-side module capabilities from browser globals in Node.js code.

A Node.js service reads a JSON configuration file from disk before starting its HTTP listener. The project uses ECMAScript modules, and the service must not depend on browser APIs or assume that file paths are resolved relative to the process's current working directory. Which implementation is the most appropriate?

Correct Answer: A. Import the Node.js file-system and URL/path utilities, derive the module-relative file location, and read the file using the appropriate file-system API.
Explanation:

Node.js provides server-side modules for filesystem operations, and an ES module can derive a location based on its module URL rather than relying on the process working directory. This avoids browser-only globals such as `window`, `document`, and `localStorage`, which are not standard Node.js globals. A browser `fetch` call does not provide a general way to read an arbitrary server-side file from disk, and a document-based path is unavailable in a Node.js process.

Question 11

New Single answer

Topic: Testing

Skill tested: Tests asynchronous JavaScript rejection behavior with assertions that await completion.

A team maintains an asynchronous JavaScript function, `loadProfile(id)`, that returns a Promise and rejects with an error when the service responds with an authorization failure. The unit test must fail if the Promise unexpectedly fulfills, and it must verify the rejection's error type. The test framework supports Promise-aware assertions. Which test pattern is most reliable?

Correct Answer: D. Use `await expect(loadProfile(id)).rejects.toBeInstanceOf(AuthorizationError)` in an async test.
Explanation:

A Promise-aware rejection assertion verifies that the returned Promise rejects and that its rejection reason is an instance of the expected error class. Awaiting the assertion ensures the test runner observes its eventual result, so unexpected fulfillment causes a failure rather than escaping after the test finishes. Synchronous inspection cannot reliably observe a later rejection. The function returns a Promise, not an error object, and swallowing any caught rejection does not verify the required error type.