Hey friends,
These 20 Salesforce JavaScript Developer practice questions are original questions weighted like the real exam's seven sections, each with the answer and an explanation in a dropdown. I wrote every one from the official exam guide objectives and MDN's JavaScript reference. None are real exam questions.
The real exam has 60 scored questions in 105 minutes, and the passing score is 65%. So aim for 13 of these 20, then read the explanation for every miss, including lucky guesses. Most questions show code and ask what it logs, so run them in your browser console afterward.
Split here: Objects, Functions, and Classes 25% (5 questions), Variables, Types, and Collections 23% (5), Browser and Events 17% (3), Asynchronous Programming 13% (3), Debugging and Error Handling 7% (2), Server Side JavaScript 8% (1), Testing 7% (1). For the topic map, see my JavaScript Developer study guide.
Variables, Types, and Collections (23%): 5 questions
Question 1. What does this code log?
- A. null array undefined
- B. object object undefined
- C. object array undefined
- D. null object undefined
Show the answer and explanation
Answer: B. typeof null is "object", a long-standing quirk of the language. Arrays are objects too, so typeof [] is "object". Use Array.isArray() to check for arrays.
Question 2. What does this code log?
- A. 3 2 2
- B. '12' 2 2
- C. 12 2 2
- D. 12 NaN 2
Show the answer and explanation
Answer: C. With +, if either side is a string, JavaScript concatenates, so 1 + '2' is the string "12". The - operator only does math, so '3' - 1 converts the string and gives 2. true converts to 1, so true + 1 is 2.
console.log prints the string 12 without quotes.
Question 3. Which of these values are falsy? Choose 3.
- A.
0 - B.
'0' - C.
'' - D.
[] - E.
NaN
Show the answer and explanation
Answer: A, C, E. The falsy values are false, 0, -0, 0n, "", null, undefined and NaN. Everything else is truthy, including the string '0' and an empty array or object.
Question 4. A developer needs a new array with only the active accounts' names. Which line does that without changing accounts?
- A.
accounts.forEach(a => a.active && a.name) - B.
accounts.filter(a => a.active).map(a => a.name) - C.
accounts.splice(1, 1) - D.
accounts.map(a => a.active ? a.name : null)
Show the answer and explanation
Answer: B. filter returns a new array of the matches, and map transforms each one. forEach returns undefined, splice mutates the original array, and the last option leaves null entries in the result.
Question 5. What does this code log?
- A. 2 {"id":7,"skip":undefined}
- B. 2 {"id":7}
- C. 2 {"id":7,"skip":null}
- D. undefined {"id":7}
Show the answer and explanation
Answer: B. JSON.parse turns the string into an object, so tags is a real array with length 2. JSON.stringify leaves out properties whose value is undefined.
Objects, Functions, and Classes (25%): 5 questions
Question 6. What does this code log?
- A. undefined, then a ReferenceError
- B. 5, then 5
- C. undefined, then undefined
- D. A ReferenceError on line 1
Show the answer and explanation
Answer: A. var declarations are hoisted and initialized to undefined, so line 1 logs undefined. let is hoisted too but stays in the temporal dead zone until its declaration runs, so reading count early throws a ReferenceError.
Question 7. What does this code log?
- A. NaN
- B. 1
- C. undefined
- D. A TypeError
Show the answer and explanation
Answer: B. Arrow functions don't have their own this. They use the this of the surrounding code, which inside incLater is counter. With a regular function callback, this would not be counter.
Question 8. What does this code log?
- A. generic
- B. woof, not generic
- C. woof, not undefined
- D. A SyntaxError
Show the answer and explanation
Answer: B. Dog overrides speak, and super.speak() calls the parent class's version.
Question 9. A module file utils.js has export default function format() {} and export const VERSION = '1.0';. Which import gets both?
- A.
import { format, VERSION } from './utils.js'; - B.
import format, { VERSION } from './utils.js'; - C.
import * as format from './utils.js'; - D.
const { format, VERSION } = require('./utils.js');
Show the answer and explanation
Answer: B. A default export is imported without braces and can take any name. Named exports go in braces. Option A looks for a named export called format, which doesn't exist.
Question 10. What does this code log?
- A. 0 1 2
- B. 3 3 3
- C. 0 0 0
- D. 2 2 2
Show the answer and explanation
Answer: B. var gives one shared i for the whole loop. The callbacks run after the loop ends, when i is 3. With let you'd get 0 1 2. More in JavaScript closures.
Browser and Events (17%): 3 questions
Question 11. A list has 500 rows, each needing a click handler. What's the most efficient approach?
- A. Add a listener to every row
- B. Add one listener to the parent list and check
event.target - C. Use inline onclick attributes
- D. Poll for clicks with setInterval
Show the answer and explanation
Answer: B. That's event delegation. Click events bubble up from the row to the parent, so one listener handles all rows, including rows added later. Use event.target.closest('li') to find the row.
Question 12. A button inside a form should run custom code and must not submit the form or let the click reach parent listeners. Which two calls are needed? Choose 2.
- A.
event.preventDefault() - B.
event.stopPropagation() - C.
return true - D.
event.cancelBubble = false
Show the answer and explanation
Answer: A, B. preventDefault stops the browser's default action, here the form submit. stopPropagation stops the event from bubbling to ancestors. They do different things.
Question 13. A developer wants code to pause in the browser at a specific line, but only when amount is over 1000. What should they use?
- A.
console.log(amount) - B. A conditional breakpoint in the browser dev tools Sources panel
- C.
alert(amount) - D.
console.table(amount)
Show the answer and explanation
Answer: B. A conditional breakpoint pauses only when its expression is true, without editing the code. Logging doesn't pause execution.
Asynchronous Programming (13%): 3 questions
Question 14. What order does this code log?
- A. A B C D
- B. A D B C
- C. A D C B
- D. A C D B
Show the answer and explanation
Answer: C. Synchronous code runs first (A, D). Then the microtask queue drains (C), and only then does the event loop take the timer task (B). See the JavaScript event loop.
Question 15. Three independent API calls must all succeed before the page renders, and the page should show an error if any fails. Which is best?
- A.
awaiteach call in sequence - B.
Promise.allwith all three - C.
Promise.anywith all three - D.
Promise.racewith all three
Show the answer and explanation
Answer: B. Promise.all starts all three together and rejects if any one rejects. Sequential awaits work but are slower. any and race settle after the first result. Compare them in Promise.all vs allSettled vs any vs race.
Question 16. What does this code log?
- A. false
- B. true
- C. 10
- D. undefined
Show the answer and explanation
Answer: B. An async function always returns a promise, even when it returns a plain value. More in async/await.
Debugging and Error Handling (7%): 2 questions
Question 17. What does this code log?
- A. parsed, done
- B. SyntaxError, done
- C. TypeError, done
- D. done
Show the answer and explanation
Answer: B. Invalid JSON makes JSON.parse throw a SyntaxError, so 'parsed' never runs. finally runs whether or not there was an error.
Question 18. Which console method shows an array of objects as a sortable table in the browser console?
- A.
console.dir - B.
console.table - C.
console.group - D.
console.assert
Show the answer and explanation
Answer: B. console.table renders arrays and objects as a table. console.group indents related messages, and console.assert logs only when its condition is false.
Server Side JavaScript (8%): 1 question
Question 19. A Node.js project needs a package for tests only, not in production. Which command adds it correctly?
- A.
npm install jest - B.
npm install --save-dev jest - C.
npm install -g jest - D.
npm init jest
Show the answer and explanation
Answer: B. --save-dev (or -D) records it under devDependencies in package.json. A plain install adds it to dependencies, and -g installs globally without recording it in the project.
Testing (7%): 1 question
Question 20. This test always passes, even when add is broken. Why?
- A. The test name is wrong
- B. It has no matcher, so nothing is asserted. Use
expect(result).toBe(5) - C. It needs to be async
- D. add must be mocked
Show the answer and explanation
Answer: B. expect(value) alone checks nothing. A test only fails when a matcher like toBe or toEqual fails. The exam's Testing objective is about spotting ineffective tests like this. For component tests, see LWC Jest testing.
How did you do?
13 or more: you're near the 65% line, so drill your weak sections. Under 13: go back to the topic guides, then retest. The fastest progress comes from rerunning the code you missed and changing one thing at a time.
Here's why I care about practice questions so much. I earned 17 Salesforce certifications, and Focus on Force was a big part of that. My early approach was study guide first, tests later. Flipping it, taking practice tests fast and often, cut my study time way down. Cert Lab is my version of that: fast testing with explanations that link to current docs.
FAQ
How many questions are on the Salesforce JavaScript Developer exam?
60 scored multiple-choice or multiple-select questions, plus up to five unscored ones, in 105 minutes.
What's the passing score?
65%.
How much does the exam cost?
US$200, and a retake is US$100, plus applicable taxes.
Are these real exam questions?
No. I wrote all 20 from the official exam objectives. They test the same skills, not the same questions.
Where should you go next?
- The JavaScript Developer study guide maps every exam section.
- JavaScript promises and closures, the two topics people miss most.
- The event loop for output-order questions.
Nick Frates, a senior Salesforce developer with 17 certifications, built the JavaScript Developer Cert Lab at nickfrates.com: rapid-fire practice questions for every exam section, each answer explained.
Cert Lab by Nick Frates
Let the JavaScript Developer Cert Lab test you to success
Lessons, flashcards, a quiz for each of the seven exam sections and full practice exams, every answer explained.
Start the JavaScript Developer Cert Lab for $9.99 →Not ready to buy? Try a free lesson and see how fast you learn.
Hope this helps!
Best,
Nick


