시험덤프
매달, 우리는 1000명 이상의 사람들이 시험 준비를 잘하고 시험을 잘 통과할 수 있도록 도와줍니다.
  / JS-Dev-101 덤프  / JS-Dev-101 문제 연습

Salesforce JS-Dev-101 시험

Salesforce Certified JavaScript Developer 온라인 연습

최종 업데이트 시간: 2026년03월09일

당신은 온라인 연습 문제를 통해 Salesforce JS-Dev-101 시험지식에 대해 자신이 어떻게 알고 있는지 파악한 후 시험 참가 신청 여부를 결정할 수 있다.

시험을 100% 합격하고 시험 준비 시간을 35% 절약하기를 바라며 JS-Dev-101 덤프 (최신 실제 시험 문제)를 사용 선택하여 현재 최신 149개의 시험 문제와 답을 포함하십시오.

 / 4

Question No : 1


catch(err => {
16 console.log("Race is cancelled.", err);
17 });
What is the value of result when Promise.race executes?

정답:
Explanation:
Comprehensive and Detailed Explanation From Exact Extract JavaScript knowledge:
Understand the three promises:
car1:
let car1 = new Promise((_, reject) =>
setTimeout(reject, 2000, "Car 1 crashed in")
);
Rejects after 2000 ms (2 seconds) with message "Car 1 crashed in".
car2:
let car2 = new Promise(resolve =>
setTimeout(resolve, 1500, "Car 2 completed")
);
Resolves after 1500 ms (1.5 seconds) with message "Car 2 completed".
car3:
let car3 = new Promise(resolve =>
setTimeout(resolve, 3000, "Car 3 completed")
);
Resolves after 3000 ms (3 seconds) with message "Car 3 completed".
Promise.race:
Promise.race([car1, car2, car3])
.then(value => {
let result = `${value} the race.`;
})
.catch(err => {
console.log("Race is cancelled.", err);
});
Behavior of Promise.race:
It settles (resolves or rejects) as soon as any of the given promises settles.
It uses the value or reason from the first settled promise.
Timing:
car2 resolves in 1500 ms.
car1 rejects in 2000 ms.
car3 resolves in 3000 ms.
The first to settle is car2 at 1500 ms, with value "Car 2 completed".
Therefore:
Promise.race resolves (not rejects) with value = "Car 2 completed". The .then handler runs; .catch is ignored because there is no rejection. Inside .then:
let result = `${value} the race.`;
Substitute value:
let result = "Car 2 completed the race.";
So, result becomes:
Car 2 completed the race.
Compare to options:
A. Car 3 completed the race.
This would be correct if car3 were the first to resolve, which it is not (it resolves last).
B. Car 2 completed the race.
Exactly matches the first-resolving promise and the constructed message.
C. Race is cancelled.
This is the prefix of the string logged in the .catch handler, but .catch never runs because the race resolves, it does not reject first.
D. Car 1 crashed in the race.
car1 is the first rejection, but since a resolution from car2 happens earlier, the race is already settled successfully before car1 rejects.
Thus the correct value of result as set in the .then block is:
Answer B
Study Guide / Concept Reference (no links): Promise.race(iterable) semantics (first settled promise wins) setTimeout and timing interactions with Promises Resolve vs reject paths and .then / .catch
Template literals and string interpolation for building result messages

Question No : 2


Refer to the following code (correcting the missing template literal backticks):
let codeName = 'Bond';
let sampleText = `The name is ${codeName}, Jim ${codeName}`;
A developer is trying to determine if a certain substring is part of a string.
Which three code statements return true?

정답:
Explanation:
Comprehensive and Detailed Explanation From Exact Extract JavaScript knowledge:
First, compute sampleText:
let codeName = 'Bond';
let sampleText = `The name is ${codeName}, Jim ${codeName}`;
The template literal evaluates to:
"The name is Bond, Jim Bond"
Now evaluate each statement:
Option A: sampleText.includes('Jim');
String.prototype.includes(substring) returns true if substring occurs anywhere in the string.
sampleText clearly contains "Jim" ("The name is Bond, Jim Bond").
So this returns true.
Option B: sampleText.includes('The', 1);
includes(searchString, position) starts searching from the given position index.
"The name is Bond, Jim Bond" has "The" starting at index 0.
Starting search at index 1 means "The" at index 0 is not considered, and there is no second "The".
So this returns false.
Option C: sampleText.includes('Jim', 4);
"Jim" appears after "The name is Bond, " which is longer than 4 characters; the index of "Jim" is well past 4.
So when searching from index 4, "Jim" is still found.
This returns true.
Option D: sampleText.indexOf('Bond') !== -1;
String.prototype.indexOf(substring) returns:
-1 if the substring is not found,
Otherwise, the starting index of the first occurrence.
"Bond" appears twice in "The name is Bond, Jim Bond".
So sampleText.indexOf('Bond') is some non-negative index (for the first occurrence).
Therefore indexOf('Bond') !== -1 is true.
Option E: sampleText.substring('Jim');
substring expects numeric indexes: substring(startIndex, endIndex?).
If given a string "Jim" as the argument, JavaScript coerces it to a number:
Number('Jim') → NaN
NaN for startIndex is treated as 0.
So sampleText.substring('Jim') is effectively sampleText.substring(0), which returns the full string "The name is Bond, Jim Bond".
This is a string, not a boolean. The question asks “which code statements return true?” This statement returns a string, not the boolean value true.
Thus, the three statements that actually return true (boolean) are:
Answer A, C, D
Study Guide / Concept Reference (no links):
Template literals and ${} interpolation
String.prototype.includes(searchString, position?)
String.prototype.indexOf(substring) and checking for !== -1
String.prototype.substring(start, end?) and argument coercion
Boolean vs non-boolean return types in string methods

Question No : 3


A developer is creating a simple webpage with a button. When a user clicks this button for the first time, a message is displayed.
The developer wrote the JavaScript code below, but something is missing. The message gets displayed every time a user clicks the button, instead of just the first time.
01 function listen(event) {
02
3 alert('Hey! I am John Doe');
4
5 }
6 button.addEventListener('click', listen);
Which two code lines make this code work as required?

정답:
Explanation:
Comprehensive and Detailed Explanation From Exact Extract JavaScript knowledge:
Requirement:
The message should be displayed only on the first click of the button.
Original behavior:
The handler listen is attached with button.addEventListener('click', listen);.
That means listen is called on every click until the listener is removed or configured otherwise.
Two correct ways to ensure the listener only fires once:
Use the once option in addEventListener
Remove the event listener after the first run inside the handler
Option C:
On line 06, add an option called once to button.addEventListener().
This means modifying line 06 to:
button.addEventListener('click', listen, { once: true });
The once: true option tells the browser:
Call the listen function at most once.
After it is called the first time, automatically remove the listener.
So:
First click: alert shows, listener is removed automatically.
Subsequent clicks: no further calls to listen, no alerts.
This satisfies the requirement.
Option D:
On line 04, use button.removeEventListener('click', listen);
This means updating the handler:
function listen(event) {
alert('Hey! I am John Doe');
button.removeEventListener('click', listen);
}
Now:
On the first click, listen is executed:
It shows the alert.
It removes itself from the button’s click listeners.
On subsequent clicks, listen is no longer registered, so nothing happens.
This also satisfies the requirement.
Why A and B are incorrect:
Option A:
On line 04, use event.stopPropagation();
event.stopPropagation() stops the event from bubbling up the DOM tree.
It does not prevent the current listener from being called again in the future.
The click handler will still run on every click; it just prevents other listeners higher in the DOM from receiving the event.
Option B:
On line 02, use event.first to test if it is the first execution.
There is no built-in event.first property in standard DOM events.
This property does not exist and will be undefined.
You would need your own external flag (let hasRun = false;) to track first execution, but that is not what B describes.
Therefore, the two correct modifications are:
Answer C, D
Explanation:
Study Guide / Concept Reference (no links): addEventListener options object: { once: true } removeEventListener to manually deregister event handlers Event propagation (event.stopPropagation) vs handler lifecycle DOM event model and listener registration

Question No : 4


Which option is true about the strict mode in imported modules?

정답:
Explanation:
Comprehensive and Detailed Explanation From Exact Extract JavaScript knowledge:
In JavaScript, ES modules (files imported using import / export) have special semantics:
All code inside a module is automatically executed in strict mode.
This is specified by the ECMAScript standard and does not require the explicit "use strict"; directive.
Effects:
You do not need to write "use strict"; at the top of a module file.
You cannot turn strict mode off for module code.
All module top-level code is treated as strict.
Now evaluate each option:
Option A:
Add the statement use non-strict; before any other statements in the module to enable notstrict mode.
There is no use non-strict; directive in JavaScript.
The only directive recognized by engines is "use strict";.
You cannot explicitly enable a “non-strict” mode with such a string.
Option B:
Imported modules are in strict mode whether you declare them as such or not.
This matches the language specification.
ES modules are always in strict mode, automatically.
This is true.
Option C:
Add the statement use strict = false; before any other statements in the module to enable notstrict mode.
use strict = false; is not a directive; it is parsed as a normal expression, and does not affect strict mode.
There is no supported way to disable strict mode in modules.
Option D:
A developer can only reference notStrict() functions from the imported module.
There is no special notStrict() restriction in modules.
Functions exported/imported in modules are simply subject to strict mode rules like the rest of the module’s code.
Therefore, the only correct statement is:
Answer B
Study Guide / Concept Reference (no links):
ES modules (import / export)
Automatic strict mode in modules
"use strict"; directive for scripts vs modules
Inability to disable strict mode in ES module code

Question No : 5


Refer to the code below:
01 async function functionUnderTest(isOK) {
02 if (isOK) return 'OK';
3 throw new Error('not OK');
4 }
Which assertion accurately tests the above code?

정답:
Explanation:
Comprehensive and Detailed Explanation From Exact Extract JavaScript knowledge:
The function:
async function functionUnderTest(isOK) {
if (isOK) return 'OK';
throw new Error('not OK');
}
Behavior:
If isOK is true:
The function resolves (fulfills the promise) with value 'OK'.
If isOK is false:
The function throws, which in an async function becomes a rejected promise with Error('not OK').
We want an assertion that accurately tests the successful path for isOK === true.
Key points about console.assert:
Signature: console.assert(condition, message?)
If condition is falsy, it logs message as an assertion failure.
If condition is truthy, nothing is logged.
We also must understand await:
await functionUnderTest(true) will resolve to the string 'OK'.
Now evaluate options.
Option A:
console.assert(await functionUnderTest(true), 'OK');
await functionUnderTest(true) → 'OK' (truthy).
console.assert('OK', 'OK');
Condition is 'OK' (truthy), so assertion passes.
The message 'OK' is only shown if the condition is falsy, which it is not.
This correctly verifies that the promise resolved (i.e., did not reject). Among the given options, this is the only one that both:
Uses await properly on the async function, and
Associates the message with the expected success "OK".
Option B:
console.assert(await (functionUnderTest(true), 'not OK'));
Inside the parentheses, the comma operator (a, b) evaluates a, discards it, and returns b.
So (functionUnderTest(true), 'not OK'):
Calls functionUnderTest(true) (returns a promise, but its result is discarded), The expression evaluates to the string 'not OK'.
Then await 'not OK' just resolves to 'not OK' immediately (not a promise).
console.assert('not OK');
Condition is 'not OK' (truthy), so the assertion passes regardless of what functionUnderTest actually does.
This does not meaningfully test the function and is misleading.
Option C:
console.assert(functionUnderTest(true), 'OK');
functionUnderTest(true) returns a Promise, not the string 'OK' directly.
A Promise object is always truthy.
So console.assert(promise, 'OK') will pass, even if the promise later rejects. Also, there is no await, so we are not actually waiting for the async result. This is not a correct way to assert on an async function’s resolved value. Option D:
console.assert(await functionUnderTest(true), 'not OK'); await functionUnderTest(true) still resolves to 'OK' (truthy).
console.assert('OK', 'not OK'); passes.
However, the message 'not OK' is the opposite of what we expect for the success case and is only used when the condition fails.
This makes the assertion logically inconsistent with the function behavior (it would show "not OK" if the assertion failed).
Therefore, the only assertion that:
Properly waits on the async function, and
Has expectation text that matches the successful behavior ('OK') is:
Answer A
Study Guide / Concept Reference (no links):
async and await behavior in JavaScript
Promises resolving vs rejecting in async functions
console.assert(condition, message) usage
Truthy and falsy values in JavaScript
Comma operator (a, b) semantics

Question No : 6


Refer to the following code block:
01 let array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11];
02 let output = 0;
03
04 for (let num of array) {
5 if (output > 10) {
6 break;
7 }
8 if (num % 2 == 0) {
9 continue;
10 }
11 output += num;
12 }
What is the value of output after the code executes?

정답:
Explanation:
Comprehensive and Detailed Explanation From Exact Extract JavaScript knowledge:
This code uses:
A for...of loop to iterate over values in array.
break to exit the loop entirely when output > 10.
continue to skip even numbers.
It sums only certain numbers into output.
Let’s walk through the loop step by step.
Initial values:
array = [1,2,3,4,5,6,7,8,9,10,11]
output = 0
Loop: for (let num of array) { ... }
First iteration: num = 1
Line 05: if (output > 10) → 0 > 10 is false → no break.
Line 08: if (num % 2 == 0) → 1 % 2 == 1, not 0, so false → no continue.
Line 11: output += num → output = 0 + 1 = 1.
Second iteration: num = 2
output > 10 → 1 > 10 is false → no break.
num % 2 == 0 → 2 % 2 == 0, so true → continue.
Because of continue, line 11 is skipped.
output remains 1.
Third iteration: num = 3
output > 10 → 1 > 10 is false.
num % 2 == 0 → 3 % 2 == 1, false → no continue.
output += num → output = 1 + 3 = 4.
Fourth iteration: num = 4
output > 10 → 4 > 10 is false.
num % 2 == 0 → 4 % 2 == 0, true → continue.
Skip sum; output remains 4.
Fifth iteration: num = 5
output > 10 → 4 > 10 is false.
num % 2 == 0 → 5 % 2 == 1, false.
output += num → output = 4 + 5 = 9.
Sixth iteration: num = 6
output > 10 → 9 > 10 is false.
num % 2 == 0 → 6 % 2 == 0, true → continue.
output remains 9.
Seventh iteration: num = 7
output > 10 → 9 > 10 is false.
num % 2 == 0 → 7 % 2 == 1, false.
output += num → output = 9 + 7 = 16.
Eighth iteration would be num = 8, but:
At the top of the loop body, line 05 is checked again:
if (output > 10) → 16 > 10 is true, so break; is executed.
When break runs:
The loop terminates immediately.
No further iterations (for num = 8, 9, 10, 11) are executed.
Therefore, output stays at 16.
Final value of output after the loop ends is 16.
This matches option A.
Why other options do not match:
B. 25: Would require adding more odd numbers (e.g., 9, 11) after 7, but the loop stops early due to output > 10.
C. 11: Would be smaller; the actual sum of 1 + 3 + 5 + 7 until break is 16.
D. 36: Would require summing many more values (e.g., most or all odd numbers up to 11), but again, the break condition stops the loop once output exceeds 10.
So:
Answer A
JavaScript knowledge / Study Guide references (concept names only, no links):
for...of loop over arrays
break statement in loops (terminating a loop early) continue statement in loops (skipping to the next iteration) Modulo operator % to test even and odd numbers Step-by-step execution and control flow in loops

Question No : 7


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.)

정답:
Explanation:
Comprehensive and Detailed Explanation From Exact Extract JavaScript knowledge:
Node.js includes a built-in command-line (CLI) debugger. To use it directly in the terminal, the standard command is:
node inspect server.js
This:
Starts server.js under the Node.js inspector.
Opens the CLI debugger right in the terminal window where you ran the command.
Lets you interactively:
Step through code
Set breakpoints
Inspect variables
Continue execution, etc.
Why B is correct:
Option B (corrected to node inspect server.js) is exactly the standard Node.js command to run a script under the CLI debugger in the current terminal.
It does not rely on any external GUI tools.
You stay entirely in the terminal to debug.
Why the other options are incorrect:
A. node start inspect server.js
There is no start subcommand like this in standard Node.js CLI.
This is not a valid Node.js debugging command.
C. node server.js --inspect
This starts Node.js with the Inspector protocol enabled and is typically used to connect external tools like Chrome DevTools or VS Code.
It does not open the CLI debugger in the current terminal. Instead, it opens a debugging port that other tools attach to.
The question specifically says “only using the terminal” and “open the CLI debugger in their current terminal window”, which points to node inspect, not --inspect.
D. node -i server.js
-i starts Node in interactive REPL mode, optionally after running a script.
This is for an interactive shell, not the Node debugger.
It does not provide breakpoint/step/next/continue debugging features like the CLI debugger.
Therefore, the only option that opens the Node.js CLI debugger in the current terminal is:
Answer B
JavaScript / Node.js knowledge / Study Guide references (concept names only, no links):
Node.js CLI debugger: node inspect <script>
Node.js inspector protocol: node --inspect
Difference between CLI debugger and DevTools-based debugging Node.js command-line options and subcommands

Question No : 8


Given the JavaScript below:
function onLoad() {
console.log("Page has loaded!");
}
Where can the developer see the log statement after loading the page in the browser?

정답:
Explanation:
Comprehensive and Detailed Explanation From Exact Extract JavaScript knowledge:
console.log() in browser-side JavaScript writes output to the browser’s JavaScript console, which is available in the browser’s Developer Tools.
In a typical browser (Chrome, Firefox, Edge, etc.), you open DevTools and go to the Console tab.
Any console.log("Page has loaded!"); executed in page JavaScript will appear there.
Why A is correct:
The function onLoad is a client-side function (runs in the browser).
When it executes, the console.log call goes to the browser’s JavaScript console, not the server.
Why the others are incorrect:
B. On the terminal console running the web server
That console shows logs from the server-side runtime (e.g., Node.js logs).
This code is clearly browser-side JavaScript (no Node.js or server context shown).
Therefore, the output does not appear in the terminal.
C. In the browser performance tools log
Performance tools (Timeline, Performance tab, etc.) show metrics about rendering, CPU time, network, etc., not generic console.log messages.
console.log messages appear in the Console tab, not in performance logs.
D. On the webpage console log
There is no built-in concept of a “webpage console log” UI rendered on the page itself by default.
Unless you explicitly code something to display logs in the DOM, console.log output is not visible on the page, only in Developer Tools.
Therefore, the correct place to see that log is:
Answer A
JavaScript knowledge / Study Guide references (concept names only, no links):
Browser Developer Tools C Console tab
console.log() in client-side JavaScript
Difference between client-side logs and server-side logs

Question No : 9


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) {
2 this.maxSpeed = maxSpeed;
3 this.color = color;
4 }
5 let carSpeed = document.getElementById('carSpeed');
6 debugger;
7 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?

정답:
Explanation:
Comprehensive and Detailed Explanation From Exact Extract JavaScript knowledge:
When execution hits the debugger; statement on line 06, JavaScript execution pauses at that point. Most modern browsers (for example, using DevTools) allow you to inspect the current scope, DOM, and various browser APIs in the console.
Let’s look at what is available precisely at line 06.
Current code state at the breakpoint:
Lines 01C04 define the Car constructor function.
Line 05 executes:
let carSpeed = document.getElementById('carSpeed');
So at line 06:
carSpeed is a variable containing a reference to a DOM element (the element with id "carSpeed").
Line 07 has not executed yet:
let fourWheels = new Car(carSpeed.value, 'red');
So fourWheels has not been created and is not accessible yet (it is in the temporal dead zone for the let declaration).
Now check each option:
Option A:
"A variable displaying the number of instances created for the Car object"
This code does not implement any mechanism to count instances of Car.
There is no static property, global counter, or similar variable tracking the number of Car instances.
At line 06, no instance of Car has even been created yet (new Car(...) is on line 07, which has not run).
Therefore, there is no such variable by default in JavaScript or DevTools.
This option is not available.
Option B:
"The information stored in the window.localStorage property"
At a breakpoint, the console is fully usable to inspect global objects.
window.localStorage is always accessible from the console (assuming standard browser context).
You can type:
window.localStorage
and inspect key/value pairs stored there.
This is independent of the current function or breakpoint line; localStorage is part of the Web Storage API on the window object.
So this information is indeed available in the console at line 06.
Option C:
"The values of the carSpeed and fourWheels variables"
At line 06:
carSpeed has been declared and assigned (line 05), so it is available, and its value (a DOM element) can be inspected.
fourWheels is declared on line 07 with let and has not yet been executed.
Variables declared with let and const are in a temporal dead zone before their declaration line completes.
At line 06, fourWheels is not yet initialized, and attempting to access it would result in a ReferenceError.
Thus, you can inspect carSpeed but not fourWheels. The option explicitly says "the values of the carSpeed and fourWheels variables", which is not correct at this breakpoint, because fourWheels is not available yet.
Option D:
"The style, event listeners and other attributes applied to the carSpeed DOM element" carSpeed holds a reference to a DOM element (document.getElementById('carSpeed')). In DevTools, you can inspect this element in several ways: Typing carSpeed in the console.
Inspecting it in the Elements panel.
From the console or Elements panel, you can view:
Its style (inline styles and computed styles).
Event listeners attached to it (using event listener viewer in DevTools).
Other attributes (id, class, etc.).
All of this is accessible at the point where execution is paused. Therefore, this information is available at the breakpoint. Conclusion:
B is available (global window.localStorage).
D is available (full inspection of the carSpeed DOM element).
A is not present in this code or environment.
C is partially wrong (only carSpeed exists; fourWheels does not yet).
So the two correct answers are:
Answer B, D
Reference of JavaScript knowledge documents or Study Guide (concept names only):
debugger statement and pausing execution
JavaScript execution context and scope at a breakpoint
let declarations and temporal dead zone
Browser DevTools console and inspection of variables
DOM access via document.getElementById and inspection of elements Web Storage API: window.localStorage

Question No : 10


Given the JavaScript below:
01 function filterDOM(searchString){
2 const parsedSearchString = searchString && searchString.toLowerCase();
3 document.querySelectorAll('.account').forEach(account => {
4 const accountName = account.innerHTML.toLowerCase();
5 account.style.display = accountName.includes(parsedSearchString) ? /* Insert code here */
6 });
7 }
Which code should replace the placeholder comment on line 05 to hide accounts that do not match the search string?

정답:
Explanation:
Comprehensive and Detailed Explanation From Exact Extract JavaScript knowledge:
Line 05 uses the conditional (ternary) operator:
condition ? valueIfTrue : valueIfFalse
In this specific code:
account.style.display = accountName.includes(parsedSearchString)
? /* valueIfTrue */ : /* valueIfFalse */;
accountName.includes(parsedSearchString) returns:
true if the accountName string contains the parsedSearchString,
false otherwise.
The requirement is:
Hide accounts that do not match the search string.
That means:
If the account name includes the search string → it should be visible.
If the account name does not include the search string → it should be hidden.
The relevant property is:
account.style.display
For the display property:
Common values for showing elements:
'block', 'inline', 'inline-block', etc.
Common value for hiding elements:
'none' (element is not rendered and takes up no space).
So we want:
When accountName.includes(parsedSearchString) is true → show the element, e.g. display = 'block'.
When false → hide the element, display = 'none'.
Therefore the assignment should be:
account.style.display = accountName.includes(parsedSearchString) ? 'block' : 'none';
This matches option A:
'block' : 'none'
Why other options are incorrect:
B. 'none' : 'block'
This would hide matching accounts and show non-matching accounts, which is the opposite of the requirement.
C. 'hidden' : 'visible'
These are not valid values for the display property; they belong to the visibility property (visibility:
'hidden' | 'visible'), not display.
D. 'visible' : 'hidden'
Same issue as C: not valid for display, and reversed logic compared to requirement.
Thus, to correctly show matching accounts and hide non-matching ones, the ternary must be:
'block' : 'none'
Reference of JavaScript knowledge documents or Study Guide (concept names only):
Conditional (ternary) operator condition ? exprIfTrue : exprIfFalse
String.prototype.includes for substring checks
DOM APIs: document.querySelectorAll and forEach on NodeLists Element styling via element.style.display CSS display property: block vs none

Question No : 11


Refer to the code below:
let productSKU = '8675309';
A developer has a requirement to generate SKU numbers that are always 19 characters long, starting with 'sku', and padded with zeros.
Which statement assigns the value sku000000008675309?

정답:
Explanation:
Comprehensive and Detailed Explanation From Exact Extract JavaScript knowledge:
We start with:
let productSKU = '8675309';
The requirement:
Final SKU string:
Length: 19 characters.
Starts with 'sku'.
Remaining characters are digits padded with zeros on the left (to reach total length). We can use String.prototype.padStart and String.prototype.padEnd: str.padStart(targetLength, padString)
If str.length < targetLength, it adds padString to the start until the length is targetLength.
str.padEnd(targetLength, padString)
Similar, but adds padString to the end.
We want a pattern like:
First, pad the numeric part out to a fixed length with zeros.
Then, pad to total length with 'sku' at the start.
Analyze Option B
productSKU = productSKU.padStart(16, '0').padStart(19, 'sku'); Step 1: productSKU.padStart(16, '0') Initial productSKU is '8675309' (length 7).
After padStart(16, '0'), we pad zeros on the left to reach length 16.
We need 16 − 7 = 9 zeros:
Result after step 1:
productSKU === '0000000008675309' // length 16
Step 2: .padStart(19, 'sku')
Now productSKU has length 16.
We call padStart(19, 'sku'):
We need 19 − 16 = 3 extra characters.
The pad string 'sku' is exactly 3 characters, so it is added as-is at the start.
Result after step 2:
productSKU === 'sku0000000008675309' // length 19
This satisfies:
Length 19.
Starts with 'sku'.
Remaining characters are zeros plus the original digits, i.e. a zero-padded numeric section.
While the literal sample sku000000008675309 in the text has a slightly different count of zeros,
Option B follows the requirement pattern:
3 characters of 'sku'
Numeric part padded with zeros to make 16 characters total for the numeric part 3 + 16 = 19 total characters
Option B matches the intended logic using padStart and padEnd.
Why the other options are incorrect
Option A:
productSKU = productSKU.padEnd(16, '0').padStart('sku');
padEnd(16, '0') produces '8675309000000000' (original number followed by zeros).
padStart('sku') is invalid usage:
padStart takes a numeric target length as the first argument, not a string.
Passing 'sku' as the first argument leads to type coercion that does not achieve the intended behavior.
This will not reliably produce the desired SKU.
Option C:
productSKU = productSKU.padEnd(16, '0').padStart(19, 'sku');
First padEnd(16, '0') from '8675309' gives '8675309000000000' (length 16, zeros at the end).
Then padStart(19, 'sku') adds 3 chars 'sku' at the front:
Result: 'sku8675309000000000'.
This string starts with 'sku', but the zeros are at the end of the digits, not padding the numeric part on the left as desired.
Option D:
productSKU = productSKU.padStart(19, '0').padStart('sku');
First padStart(19, '0') pads zeros at the left to make the length 19.
Then padStart('sku') again incorrectly uses a string where a numeric targetLength is required.
This will not produce the correct SKU format.
Therefore, the only option that correctly uses padStart to create a 16-character zero-padded numeric portion and then a 19-character string starting with 'sku' is:
Answer B
Reference / Study Guide concepts (no links):
String.prototype.padStart(targetLength, padString)
String.prototype.padEnd(targetLength, padString)
String length calculations
Left-padding numeric strings with zeros
Building prefixed identifiers with fixed total length

Question No : 12


Refer to the code below:
01 const addBy = ?
02 const addByEight = addBy(8);
03 const sum = addByEight(50);
Which two functions can replace line 01 and return 58 to sum?

정답:
Explanation:
Comprehensive and Detailed Explanation From Exact Extract JavaScript knowledge:
We want:
const addByEight = addBy(8);
const sum = addByEight(50);
And we need sum to be 58.
That means:
addBy(8) must return a function.
That returned function, when called with 50, must compute 8 + 50.
So addBy must be a higher-order function that returns another function capturing num1 and later using it with num2 (a closure).
Option A
const addBy = function(num1) {
return function(num2) {
return num1 + num2;
}
}
Step-by-step:
Call addBy(8):
num1 is 8.
The function returns an inner function: function(num2) { return num1 + num2; }.
So addByEight becomes this inner function, with num1 closed over as 8.
Then call addByEight(50):
num2 is 50.
The body computes num1 + num2, i.e., 8 + 50 = 58.
Therefore, with Option A in place:
const addByEight = addBy(8); // returns inner function
const sum = addByEight(50); // 58
So sum is 58. Option A is correct.
Option D (corrected)
const addBy = (num1) => {
return function(num2) {
return num1 + num2;
}
}
This is essentially the same logic expressed with an arrow function for the outer function:
Call addBy(8):
num1 is 8.
Returns the inner function function(num2) { return num1 + num2; }.
Call addByEight(50):
num2 is 50.
Computes num1 + num2 → 8 + 50 = 58.
So again:
const addByEight = addBy(8); // inner function with num1 = 8 const sum = addByEight(50); // 58 Option D is also correct.
Thus, A and D are the two functions that satisfy the requirement.
Why B and C are incorrect
Option B:
const addBy = function(num1) {
return num1 * num2;
}
This does not return a function; it returns a value.
addBy(8) returns 8 * num2, but num2 is not defined in this scope, which would cause a ReferenceError.
Also, addByEight would be a number (if num2 existed), not a function, so addByEight(50) would fail.
Option C:
const addBy = (num1) => num1 + num2;
Again, addBy returns a value, not a function.
addBy(8) returns 8 + num2, but num2 is not defined, so this is also invalid due to ReferenceError.
addByEight would be a number (or error), not a function.
Neither B nor C creates the required closure nor returns a function to be called later.
Reference / Study Guide concepts (no links):
Higher-order functions in JavaScript
Closures: inner functions capturing outer variables (num1)
Arrow functions vs function expressions
Returning functions from functions (function factories / currying)
Scope and ReferenceError when a variable is not defined

Question No : 13


A developer creates a class that represents a news story based on the requirements that a Story should have a body, author, and view count.
The code is shown below:
01 class Story {
2 // Insert code here
3 this.body = body;
4 this.author = author;
5 this.viewCount = viewCount;
6 }
7 }
Which statement should be inserted in the placeholder on line 02 to allow for a variable to be set to a new instance of a Story with the three attributes correctly populated?

정답:
Explanation:
Comprehensive and Detailed Explanation From Exact Extract JavaScript knowledge:
In ES6 class syntax, the special method used to initialize a new instance is called constructor.
A class definition syntax:
class ClassName {
constructor(param1, param2) {
this.prop1 = param1;
this.prop2 = param2;
}
}
The constructor method:
Is called automatically when you create a new instance with new ClassName(...).
Receives the arguments passed in the new expression.
Assigns values to this to set instance properties.
Applying this to Story
We want to be able to write:
const article = new Story('Some body', 'Author Name', 100); and have:
article.body === 'Some body'
article.author === 'Author Name'
article.viewCount === 100
To achieve this, the class must have:
class Story {
constructor(body, author, viewCount) {
this.body = body;
this.author = author;
this.viewCount = viewCount;
}
}
So the correct line 02 is:
constructor(body, author, viewCount) {
Why the other options are incorrect
A. constructor() {
This defines a constructor with no parameters.
The lines inside the constructor use body, author, and viewCount, which would be undefined unless they exist in an outer scope (they normally do not).
This would lead to the instance properties being set to undefined in normal usage.
B. super(body, author, viewCount) {
super(...) is used inside a constructor of a subclass to call the parent class constructor. You cannot use super(...) { as a method definition; this is invalid syntax in a class body. Additionally, Story as given is not shown extending any class, so super is inappropriate here. C. function Story(body, author, viewCount) {
Inside a class definition, you do not use the function keyword to define methods.
function Story(...) here would be invalid syntax in a class body.
Even if it were allowed, the special constructor method for a class is named constructor, not the class name.
Therefore, only:
constructor(body, author, viewCount) {
correctly declares the constructor for the Story class and ensures instances created with new Story(body, author, viewCount) have all three properties populated.
Reference / Study Guide concepts (no links):
ES6 class syntax
constructor method in classes
this and instance properties in classes
Difference between class constructors and regular functions
Invalid use of super and function inside class bodies

Question No : 14


Given the following code:
01 let x = null;
02 console.log(typeof x);
What is the output of line 02?

정답:
Explanation:
Comprehensive and Detailed Explanation From Exact Extract JavaScript knowledge:
This question focuses on the typeof operator and how JavaScript represents the type of the value null.
Declaration on line 1:
let x = null;
Here:
x is explicitly assigned the value null.
In JavaScript, null is a special primitive value that represents “no value” or “empty value”.
Line 2:
console.log(typeof x);
The typeof operator returns a string indicating the type of the operand. For example:
typeof 1 returns "number"
typeof "hello" returns "string"
typeof true returns "boolean"
typeof undefined returns "undefined"
typeof {} returns "object"
typeof [] returns "object" (arrays are objects)
typeof function() {} returns "function"
For null, due to an early design decision in JavaScript, the result is:
typeof null === "object"
This is a known historical quirk of the language:
Although null is a primitive and conceptually means “no object”, typeof null returns the string "object".
Therefore, typeof x when x is null evaluates to "object".
So on line 2, the value printed is:
"object"
This matches option A.
The incorrect options are:
B. "undefined": would be typeof x if x were undefined, not null.
C. "x": typeof returns a string describing the type of the value, not the variable name.
D. "null": although intuitive, JavaScript does not return "null" for typeof null; it returns "object" instead.
Therefore, the correct answer is:
Answer A
Explanation:
JavaScript knowledge / study guide reference concepts:
typeof operator and its return values
Primitive types in JavaScript (null, undefined, number, string, boolean, symbol, bigint)
Historical behavior: typeof null returning "object"
Difference between null and undefined in JavaScript

Question No : 15


Refer to the code below:
01 function myFunction(reassign) {
2 let x = 1;
3 var y = 1;
4
5 if (reassign) {
6 let x = 2;
7 var y = 2;
8 console.log(x);
9 console.log(y);
10 }
11
12 console.log(x);
13 console.log(y);
14 }
What is displayed when myFunction(true) is called?

정답:
Explanation:
Comprehensive and Detailed Explanation From Exact Extract JavaScript knowledge:
This question tests understanding of let (block scope) and var (function scope) in JavaScript.
Initial declarations in the function:
let x = 1; // line 2
var y = 1; // line 3
Here:
x is declared with let, so it is block-scoped to the function body.
y is declared with var, so it is function-scoped to the entire function. Inside the if (reassign) block (and since reassign is true, we enter it): if (reassign) {
let x = 2; // line 6
var y = 2; // line 7
console.log(x); // line 8
console.log(y); // line 9
}
Detailed behavior:
let x = 2; on line 6 creates a new block-scoped variable x that exists only inside the if block. It does not change the outer x declared on line 2.
var y = 2; on line 7 declares y with var again, but var is function-scoped. This effectively reassigns the same y defined on line 3 for the entire function. After this line, y is 2 everywhere in the function.
Now, inside the if block:
console.log(x); (line 8) logs the inner block-scoped x, which is 2. console.log(y); (line 9) logs y, which is the function-scoped y that was set to 2.
So the first two outputs are:
2
2
After the if block, execution continues:
console.log(x); // line 12
console.log(y); // line 13
Outside the if block:
The block-scoped let x = 2; no longer exists; it was only visible inside the if block.
The outer let x = 1; (line 2) is still in scope and has not been changed.
Thus:
console.log(x); (line 12) logs the outer x, which is still 1.
console.log(y); (line 13) logs y which, due to var y = 2; inside the if, is now 2 for the whole function.
Therefore, when myFunction(true) is called, the output in order is:
2 (inner x in if)
2 (function-scoped y after reassignment)
1 (outer x after if)
2 (function-scoped y remains 2) This corresponds to:
Answer B (2 2 1 2)
JavaScript knowledge / study guide reference concepts: let declarations and block scope
var declarations and function scope Shadowing of variables with let inside a block
Re-declaration and reassignment of var within a function Execution order of statements and console output

 / 4