Salesforce certification · Exam Salesforce-JavaScript-Developer

Salesforce-JavaScript-Developer Mock Exam

Salesforce JavaScript Developer - JS-Dev-101

Free Salesforce-JavaScript-Developer questions on Debugging and Error Handling, each with the answer and an explanation.

20 questions · 33 minutes · free, no sign-up

Debugging and Error Handling questions

1–3 of 3 free
Question 1 Choose 2
A developer is asked to fix some bugs reported by users. To do that, the developer adds a breakpoint for debugging.

01 function Car(maxSpeed, color) {

02 this.maxSpeed = maxSpeed;

03 this.color = color;

04 }

05 let carSpeed = document.getElementById( ' carSpeed ' );

06 debugger;

07 let fourWheels = new Car(carSpeed.value, ' red ' );

When the code execution stops at the breakpoint on line 06, which two types of information are available in the browser console?
Show answerHide answer

Correct answer: B, D The information stored in the window.localStorage propertyThe style, event listeners and other attributes applied to the carSpeed DOM element

Explanation

Explanation:
This question tests your understanding of browser debugging tools, specifically what information is accessible via the console when execution pauses at a debugger statement. At line 06, the code has not yet executed line 07, so fourWheels has not been instantiated. The browser console provides full access to the current scope, global objects, and DOM element properties at the breakpoint.

Correct Options:

B. The information stored in the window.localStorage property –
Correct. At the breakpoint on line 06, the browser console has full access to all global objects, including window.localStorage. Developers can query localStorage directly in the console to inspect stored key-value pairs. This is always available regardless of where execution pauses.

D. The style, event listeners and other attributes applied to the carSpeed DOM element –
Correct. The carSpeed variable is already assigned on line 05 because it executed before the breakpoint. In the console, developers can inspect this DOM element using console.dir(carSpeed) or explore it through the Elements panel. All its properties, including styles and event listeners, are fully accessible at this point.

Incorrect Options:

A. variable displaying the number of instances created for the Car object –
Incorrect. JavaScript does not automatically track instance counts for constructor functions. The Car function has no static counter property implemented. At line 06, fourWheels hasn't even been created yet (line 07 executes after the breakpoint), so instance count information is neither available nor tracked by default.

C. The values of the carSpeed and fourWheels variables –
Incorrect. While carSpeed is accessible (it was assigned on line 05), fourWheels has not been assigned yet because the breakpoint on line 06 pauses execution before line 07 runs. Therefore, fourWheels is undefined at this point, making this option partially incorrect.

Reference:

MDN Web Docs – debugger statement and browser debugging tools

Google Chrome DevTools – Console and Sources panel documentation

Salesforce Trailhead – Debugging Lightning Web Components using browser developer tools
Question 2 Choose 1
A developer needs to debug a Node.js web server because a runtime error keeps occurring at one of the endpoints.

The developer wants to test the endpoint on a local machine and make the request against a local server to look at the behavior. In the source code, the server.js file will start the server. The developer wants to debug the Node.js server only using the terminal.

Which command can the developer use to open the CLI debugger in their current terminal window?

(With corrected typing errors: node_inspect # node inspect, node_start_inspect # node start inspect.)
Show answerHide answer

Correct answer: B node inspect server.js

Explanation

Explanation:
This question tests your knowledge of Node.js debugging options, specifically the built-in CLI debugger. The developer wants to debug the Node.js server using only the terminal (CLI debugger), not the Chrome DevTools inspector. The node inspect command launches the built-in command-line debugger, allowing developers to set breakpoints, step through code, and inspect variables directly in the terminal without opening a browser.

Correct Option:

B. node inspect server.js –
Correct. The node inspect command is the correct syntax to start the Node.js built-in CLI debugger. It launches the script (server.js) in debugging mode and opens an interactive debugger prompt in the same terminal window. This allows the developer to use debug commands like cont, next, step, list, and repl to troubleshoot the runtime error at the endpoint, all within the terminal without needing a browser.

Incorrect Options:

A. node start inspect server.js –
Incorrect. The start subcommand is invalid and not recognized by Node.js. The correct command is node inspect server.js without the word start. This option likely confuses the debugger command with npm scripts (e.g., npm start) or misremembers the syntax. Executing this would result in a syntax error or an unrecognized command.

C. node server.js --inspect –
Incorrect. The --inspect flag enables the Chrome DevTools inspector protocol, which requires a browser to attach to the debugging port. While this does start the server in debug mode, it opens a WebSocket inspector that is intended for use with Chrome DevTools, not a CLI debugger in the same terminal. This does not meet the requirement of using "only the terminal."

D. node -i server.js –
Incorrect. The -i flag is used to start an interactive REPL session, not a debugger. When used with a script argument, Node.js will execute the script and then enter REPL mode after completion. It does not enable debugging functionality, and no breakpoints or debug commands are available. This is not a valid debugger command.

Reference:

Node.js Official Documentation – Command-line options for debugging

Node.js Official Documentation – Debugger (built-in CLI debugger)

MDN Web Docs – Node.js debugging strategies

Salesforce Trailhead – Debugging Node.js Applications
Question 3 Choose 1
A developer wrote the following code:

01 let x = object.value;

02

03 try {

04 handleObjectValue(x);

05 } catch(error) {

06 handleError(error);

07 }

The developer has a getNextValue function to execute after handleObjectValue(), but does not want to execute getNextValue() if an error occurs. How can the developer change the code to ensure this behavior?
Show answerHide answer

Correct answer: B 03 try {

04 handleObjectValue(x);

05 getNextValue();

06 } catch(error) {

07 handleError(error);

08 }

Explanation

Explanation:
This question tests your understanding of JavaScript's try...catch statement and control flow. The developer wants getNextValue() to execute only after handleObjectValue() completes successfully, but not if an error occurs. In a try...catch block, code placed inside the try block after the function call executes sequentially only if no error is thrown. If an error occurs, execution jumps to the catch block, skipping any remaining code in the try block. Therefore, placing getNextValue() inside the try block after handleObjectValue() achieves the desired behavior.

Correct Option:

B.
text
try {
handleObjectValue(x);
getNextValue();
} catch(error) {
handleError(error);
}

This is correct. By placing getNextValue() inside the try block immediately after handleObjectValue(), it will only execute if handleObjectValue() completes without throwing an error. If an error is thrown, execution jumps directly to the catch block, skipping getNextValue() entirely. This matches the requirement precisely.

Incorrect Options:

A. try { handleObjectValue(x); } catch(error) { handleError(error); } then { getNextValue(); } –
Incorrect. There is no then clause associated with try...catch in JavaScript. The then method is used with Promises, not with try...catch statements. This syntax would cause a syntax error, so the code would not execute at all.

C. try { handleObjectValue(x); } catch(error) { handleError(error); } getNextValue(); –
Incorrect. In this version, getNextValue() is placed outside the try...catch block entirely. This means it will execute regardless of whether an error occurs in the try block. If handleObjectValue() throws an error, getNextValue() will still run after the catch block, which violates the requirement.

D. try { handleObjectValue(x); } catch(error) { handleError(error); } finally { getNextValue(); } –
Incorrect. The finally block executes always, regardless of whether an error was thrown or caught. This means getNextValue() would run even if handleObjectValue() throws an error, which does not meet the requirement. The finally block is used for cleanup operations that must happen regardless of success or failure.

Reference:

MDN Web Docs – try...catch statement and control flow

MDN Web Docs – finally block (executes regardless of errors)

MDN Web Docs – Error handling in JavaScript

Salesforce Trailhead – JavaScript Essentials: Error Handling

That's the last free question in Debugging and Error Handling

You've seen the free 30% (3 of 11 questions). Full access unlocks every question and full-length Salesforce-JavaScript-Developer mock exams (65 questions, 105 minutes), a different mock on every attempt.

Unlock full mock exam
Full mock exam

Sit the Salesforce-JavaScript-Developer exam before exam day

Full-length mocks with the same number of questions and the same time limit as the real Salesforce-JavaScript-Developer exam. Every attempt draws a new set of questions from the full bank, so you can keep going until you pass comfortably.

Get full Salesforce-JavaScript-Developer mock exam
  • 65questions per mock
  • 105 mintime limit
  • 147questions in the bank
  • Newmock on every attempt