Salesforce Salesforce JS-Dev-101 PDF Salesforce Salesforce JS-Dev-101 PDF Questions Available Here at: https://www.certification-exam.com/en/study-guides/salesforce-exam/js-dev-101- questions/quiz.html Enrolling now you will get access to 289 questions in a unique set of Salesforce JS-Dev-101 Question 1 An API returns the JSON text `[{"id":"A1","amount":"12.50"}]`. The application must produce a new JavaScript array in which `amount` is a number, while leaving the parsed source objects unchanged. Which implementation meets both requirements? Options: A. const records = JSON.parse(response); records.forEach(record => { record.amount = Number(record.amount); }); B. const records = response.map(record => ({ ...record, amount: Number(record.amount) })); C. const records = JSON.parse(response).map(record => ({ ...record, amount: Number(record.amount) })); D. const records = JSON.stringify(response).map(record => ({ ...record, amount: Number(record.amount) })); Answer: C Explanation: The response must first be parsed from JSON text into an array. `map` then creates a new array, and the object spread creates a new object for each record before converting `amount` to a number. Option A mutates the parsed objects, while options B and D attempt to use array methods on strings. Question 2 Consider the following JavaScript code: const first = { status: "ready" }; const second = first; Salesforce Salesforce JS-Dev-101 PDF https://www.certification-exam.com/ second.status = "done"; console.log(first.status === "done"); What value is printed? Options: A. true B. false C. undefined D. A TypeError is thrown Answer: A Explanation: Objects are reference values, so assigning first to second makes both variables refer to the same object. Updating the status property through second also changes the object observed through first. The strict equality comparison therefore evaluates to true. The const declaration prevents reassignment of the variable, but it does not make the object's properties immutable. Question 3 A list renders its items dynamically after the page loads. A click handler is attached to the list container, and the handler should process clicks on buttons inside each item, including buttons added later. Which implementation best supports this requirement? Options: A. Attach a separate click handler to every item button immediately after each button is created B. Attach one click handler to the container and use event.target.closest('button') inside the handler C. Attach the handler to the document and prevent propagation from every unrelated element D. Attach the handler to the container and read event.currentTarget as the clicked button Answer: B Explanation: This uses event delegation: the container receives bubbled click events, and event.target.closest('button') identifies the clicked button even when the button was added after the handler was registered. event.currentTarget refers to the container, not the originating button. Question 4 Salesforce Salesforce JS-Dev-101 PDF https://www.certification-exam.com/ Consider the following JavaScript code: let attempts = 0; let approved = false; while (attempts < 3 && !approved) { attempts++; if (attempts === 2) { approved = true; } } What are the final values of attempts and approved? Options: A. attempts is 1 and approved is false B. attempts is 2 and approved is true C. attempts is 3 and approved is true D. attempts is 3 and approved is false Answer: B Explanation: The loop runs while both conditions are true. On the first iteration, attempts becomes 1 and approval remains false. On the second iteration, attempts becomes 2, causing approved to become true. The next condition check fails because !approved is false, so the loop stops before a third iteration. Question 5 A developer needs an array containing the unique values from a Set and then separates its first value from the remaining values. What are the values of `first` and `rest` after this code runs? ```javascript const unique = new Set([2, 4, 2, 6]); const [first, ...rest] = [...unique]; ``` Options: A. `first` is `2` and `rest` is `[2, 4, 6]` B. `first` is `[2, 4, 6]` and `rest` is `[]` C. `first` is `2` and `rest` is `[4, 6]` Salesforce Salesforce JS-Dev-101 PDF https://www.certification-exam.com/ D. `first` is `4` and `rest` is `[2, 6]` Answer: C Explanation: A Set is iterable and removes the duplicate `2`, while preserving insertion order, so `[...unique]` produces `[2, 4, 6]`. Array destructuring assigns the first element to `first`; the rest element collects the remaining elements into a new array, producing `first === 2` and `rest === [4, 6]`. Question 6 A module named `utils.js` contains `export const formatDate = ...;` and `export default function buildLabel() { ... }`. Which statement correctly imports both exports into another ES module? Options: A. import { buildLabel, formatDate } from './utils.js'; B. import buildLabel, { formatDate } from './utils.js'; C. import { default as formatDate, buildLabel } from './utils.js'; D. import default buildLabel, formatDate from './utils.js'; Answer: B Explanation: A default export is imported without braces and may be given any local name, while a named export must appear inside braces using its exported name. Therefore, `buildLabel` is imported as the default export and `formatDate` as a named export. Question 7 A JavaScript module calculates a value by calling a browser API directly inside the function. Unit tests become dependent on the real browser environment and are difficult to isolate. Which refactoring most improves the code's testability? Options: A. Move the browser API call into the test so production code remains unchanged B. Pass the browser-dependent operation into the function as a dependency C. Replace the unit test with a manual test in the browser D. Add more logging statements around the browser API call Answer: B Explanation: Dependency injection allows the test to provide a controlled stub or mock instead of invoking the real Salesforce Salesforce JS-Dev-101 PDF https://www.certification-exam.com/ browser API, isolating the unit under test. Moving the call into the test does not change the production dependency, manual testing does not provide repeatable unit isolation, and logging helps diagnosis but does not remove the dependency. Question 8 A JavaScript component processes an identifier as follows: const input = " SFDC-042 "; const value = input.trim(); const match = /^([A-Z]+)-(\d+)$/.exec(value); const result = `${match[1]}-${Number(match[2])}`; What is the value of result? Options: A. SFDC-042 B. SFDC-42 C. SFDC-undefined D. SFDC-NaN Answer: B Explanation: trim() removes the surrounding spaces, and the regular expression captures "SFDC" in group 1 and "042" in group 2. Number("042") produces the numeric value 42, so the template literal produces "SFDC-42". Question 9 A browser executes the following code: console.log("A"); setTimeout(() => console.log("B"), 0); Promise.resolve().then(() => console.log("C")); console.log("D"); What is the order in which the values are printed? Options: A. A, D, C, B B. A, C, D, B C. A, B, D, C Salesforce Salesforce JS-Dev-101 PDF https://www.certification-exam.com/ D. A, D, B, C Answer: A Explanation: The synchronous statements print A and D first. The Promise handler is placed in the microtask queue, which is processed before the timer task, so C is printed before the setTimeout callback prints B. Question 10 Consider the following JavaScript code: let makeCounter = () => { let count = 0; return () => ++count; }; const first = makeCounter(); const second = makeCounter(); first(); first(); second(); What values will the next calls to `first()` and `second()` return? Options: A. The next calls return 3 and 2, respectively. B. The next calls return 2 and 2, respectively. C. The next calls return 3 and 1, respectively. D. The next calls return 1 and 3, respectively. Answer: A Explanation: Each call to `makeCounter()` creates a separate lexical environment containing its own `count`. The `first` closure has already incremented its private count twice, so its next call returns 3. The `second` closure has been called once, so its next call returns 2. Would you like to see more? Don't miss our Salesforce JS- Dev-101 PDF file at: https://www.certification-exam.com/en/pdf/salesforce-pdf/js-dev-101-pdf/ Salesforce Salesforce JS-Dev-101 PDF https://www.certification-exam.com/