Docsity

Salesforce Certified JavaScript Developer I — Modern ECMAScript Types, Functions & Closur, Exams of Javascript programming

Toggle sidebar
bg1
Salesforce Certified JavaScript Developer I — Modern ECMAScript Types,
Functions & Closures, Objects & Classes, Arrays & Collections,
Asynchronous Programming, Browser & DOM APIs, Node.js Runtime,
Automated Testing & Web Security Comprehensive Practice Exam
1. Exam Overview
• Exam Title: Salesforce Certified JavaScript Developer I Comprehensive Practice Exam
• Total Questions: 250 Multiple-Choice Questions (4 Options Each)
• Delivery Format: Modular Practice Bank (5 Batches of 50 Questions)
• Recommended Time Allocation: 375 Minutes (1.5 minutes per question for full simulation, or 75
minutes per 50-question batch)
• Passing Benchmark: 70% (175 / 250 correct responses)
• Assessment Focus: This examination evaluates deep practical mastery of modern JavaScript (ES6+), type
coercion, lexical scoping, prototypes and classes, functional array transformations, Promises and
async/await concurrency, Browser/DOM event architecture, Node.js execution and package
management, unit testing frameworks, and web application security.
2. Content Blueprint
Domain
Topic Area
Question
Range
Weight
Key Concepts Tested
Domain 1
Variables, Data Types,
Coercion & Operators
Q1 – Q35
14%
let/const/var, TDZ, primitives vs. references,
type coercion, equality (== vs ===), Symbol,
BigInt, optional chaining, nullish coalescing
Domain 2
Functions, Scope, Closures &
Execution Context
Q36 – Q70
14%
Lexical scope, hoisting, closures, this
binding, call/apply/bind, arrow functions,
IIFEs, currying, rest/spread, default
parameters
Domain 3
Objects, Prototypes, Classes &
Modules
Q71 – Q105
14%
Object descriptors, Object.freeze/seal,
prototype chain, ES6 classes, inheritance,
static/private fields, destructuring, ES
Modules vs. CommonJS
Domain 4
Arrays, Iterators, Generators
& Keyed Collections
Q106 – Q135
12%
map/filter/reduce, flat/flatMap,
find/some/every, sort immutability, Set,
Map, WeakSet, WeakMap, custom iterables,
Symbol.iterator, generators
Domain 5
Asynchronous JavaScript &
Event Loop
Q136 – Q170
14%
Call stack, Web APIs, macrotask vs.
microtask queues, Promises,
Promise.all/allSettled/race/any,
async/await, error propagation, Fetch API
Domain 6
Browser Environment, DOM &
Events
Q171 – Q200
12%
DOM traversal/manipulation, event
bubbling & capturing, delegation,
preventDefault vs. stopPropagation, Web
Storage, cookies, history, CORS
Domain 7
Node.js Runtime, CLI &
Q201 – Q225
10%
Node event loop, process/Buffer/Streams,
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28

Partial preview of the text

Download Salesforce Certified JavaScript Developer I — Modern ECMAScript Types, Functions & Closur and more Exams Javascript programming in PDF only on Docsity!

Salesforce Certified JavaScript Developer I — Modern ECMAScript Types,

Functions & Closures, Objects & Classes, Arrays & Collections,

Asynchronous Programming, Browser & DOM APIs, Node.js Runtime,

Automated Testing & Web Security Comprehensive Practice Exam

1. Exam Overview

- Exam Title: Salesforce Certified JavaScript Developer I Comprehensive Practice Exam - Total Questions: 250 Multiple-Choice Questions (4 Options Each) - Delivery Format: Modular Practice Bank (5 Batches of 50 Questions) - Recommended Time Allocation: 375 Minutes (1.5 minutes per question for full simulation, or 75 minutes per 50-question batch) - Passing Benchmark: 70% (175 / 250 correct responses) - Assessment Focus: This examination evaluates deep practical mastery of modern JavaScript (ES6+), type coercion, lexical scoping, prototypes and classes, functional array transformations, Promises and async/await concurrency, Browser/DOM event architecture, Node.js execution and package management, unit testing frameworks, and web application security.

2. Content Blueprint

Domain Topic Area Question Range Weight Key Concepts Tested Domain 1 Variables, Data Types, Coercion & Operators Q1 – Q35 14% let/const/var, TDZ, primitives vs. references, type coercion, equality (== vs ===), Symbol, BigInt, optional chaining, nullish coalescing Domain 2 Functions, Scope, Closures & Execution Context Q36 – Q70 14% Lexical scope, hoisting, closures, this binding, call/apply/bind, arrow functions, IIFEs, currying, rest/spread, default parameters Domain 3 Objects, Prototypes, Classes & Modules Q71 – Q105 14% Object descriptors, Object.freeze/seal, prototype chain, ES6 classes, inheritance, static/private fields, destructuring, ES Modules vs. CommonJS Domain 4 Arrays, Iterators, Generators & Keyed Collections Q106 – Q135 12% map/filter/reduce, flat/flatMap, find/some/every, sort immutability, Set, Map, WeakSet, WeakMap, custom iterables, Symbol.iterator, generators Domain 5 Asynchronous JavaScript & Event Loop Q136 – Q170 14% Call stack, Web APIs, macrotask vs. microtask queues, Promises, Promise.all/allSettled/race/any, async/await, error propagation, Fetch API Domain 6 Browser Environment, DOM & Events Q171 – Q200 12% DOM traversal/manipulation, event bubbling & capturing, delegation, preventDefault vs. stopPropagation, Web Storage, cookies, history, CORS Domain 7 Node.js Runtime, CLI & Q201 – Q225 10% Node event loop, process/Buffer/Streams,

Package Management fs/path/events modules, npm/npx, package.json, semantic versioning, environment variables Domain 8 Testing, Debugging, Error Handling & Security Q226 – Q250 10% try/catch/finally, custom Error subclasses, strict mode, Chrome DevTools, Jest/Mocha assertions & mocks, XSS, CSRF, prototype pollution, CSP

3. How to Use This Exam

- Simulated Exam Mode: Complete one 50-question batch within 75 minutes without running code in a console or consulting external references to simulate certification pacing. - Code-Trace Verification: For output-prediction questions, trace variable scopes, microtask ordering, and type coercion step by step on paper before checking the highlighted solution. - Guided Study Mode: Review the bold green highlighted answer and detailed rationale after each question to understand why edge cases behave as specified by the ECMAScript standard. - Domain Remediation: Map missed questions back to the Content Blueprint table above to pinpoint specific weak areas for targeted coding drills.

4. Reference Materials

  • ECMA-262 Specification — ECMAScript Language Specification (TC39 Standard)
  • MDN Web Docs — JavaScript Guide, Standard Built-in Objects, Web APIs, and DOM Reference
  • Salesforce Trailhead — Prepare for Your Salesforce JavaScript Developer I Credential Trailmix
  • Salesforce Certified JavaScript Developer I Exam Guide — Official Salesforce Credential Documentation
  • Node.js Official Documentation — Core Modules, Event Loop, Timers, and Package Management Guides
  • You Don't Know JS Yet (Kyle Simpson) — Scope & Closures, Objects & Classes, and Sync & Async

Question 4 Which statement accurately describes the Nullish Coalescing Operator (??)? A) It returns the right-hand operand whenever the left-hand operand is any falsy value (0, '', false, NaN). B) [CORRECT ANSWER] It returns the right-hand operand only when the left-hand operand is null or undefined. C) It converts both operands to booleans before evaluating. D) It throws a TypeError if the left-hand operand is NaN. Rationale: Unlike logical OR (||), which falls back on all falsy values including 0 and '', the nullish coalescing operator (??) only triggers fallback when the left side is strictly null or undefined. Question 5 What is the output of console.log(0.1 + 0.2 === 0.3) in JavaScript? A) true B) [CORRECT ANSWER] false C) NaN D) TypeError Rationale: JavaScript represents all standard numbers as IEEE 754 double-precision 64-bit binary floating- point values. In binary floating-point arithmetic, 0.1 + 0.2 equals 0.30000000000000004, so strict equality with 0.3 returns false. Question 6 Which built-in method reliably determines whether a value is strictly NaN without performing implicit type coercion? A) isNaN(value) B) [CORRECT ANSWER] Number.isNaN(value) C) value === NaN D) typeof value === 'NaN' Rationale: Global isNaN('hello') coerces its argument to a number first and returns true. Number.isNaN(value) does not coerce and returns true only if the value is of type Number and is NaN. Question 7 What happens when you attempt to reassign a property on an object declared with const user = { name: 'Ada' }? A) A TypeError is thrown at runtime because const makes objects immutable. B) [CORRECT ANSWER] The property mutation succeeds because const only prevents reassigning the variable binding itself. C) A SyntaxError is raised during parsing. D) The property assignment fails silently in non-strict mode. Rationale: const creates a constant reference (binding) to the object in memory, not an immutable value. Properties inside the referenced object can still be modified unless Object.freeze() is applied.

Question 8 What is the result of [] == ![] in JavaScript? A) false B) [CORRECT ANSWER] true C) TypeError D) SyntaxError Rationale: ![] evaluates to false because arrays are truthy objects. Then [] == false coerces false to 0, and [] coerces via .toString() to '', which coerces to 0. 0 == 0 evaluates to true. Question 9 Which primitive data type was introduced in ES2020 to represent integers larger than Number.MAX_SAFE_INTEGER (2^53 - 1)? A) LongInt B) Decimal C) [CORRECT ANSWER] BigInt D) SafeInt Rationale: BigInt (created by appending n to an integer literal like 9007199254740993n or calling BigInt()) provides arbitrary-precision integer arithmetic beyond Number.MAX_SAFE_INTEGER. Question 10 What occurs when you mix a BigInt and a standard Number using the + operator (10n + 5)? A) 15n B) 15 C) [CORRECT ANSWER] A TypeError is thrown because BigInt and Number cannot be implicitly mixed in arithmetic operations. D) "105" Rationale: ECMAScript prohibits implicit coercion between BigInt and Number in arithmetic operators (+, -, *, /) to prevent silent precision loss, throwing a TypeError unless explicitly converted. Question 11 How does Object.is(NaN, NaN) compare to NaN === NaN? A) Both return false. B) Both return true. C) [CORRECT ANSWER] Object.is(NaN, NaN) returns true, whereas NaN === NaN returns false. D) Object.is(NaN, NaN) returns false, whereas NaN === NaN returns true. Rationale: Object.is() implements the SameValue algorithm: it treats NaN as equal to NaN (true) and distinguishes +0 from -0 (Object.is(+0, - 0) is false), unlike ===.

Question 16 What is the primary characteristic of values created with Symbol('id')? A) Two calls to Symbol('id') return the exact same primitive value. B) [CORRECT ANSWER] Every Symbol() call creates a guaranteed unique primitive value, even with identical descriptions. C) Symbol properties are included by default in JSON.stringify() and for...in loops. D) Symbols can be implicitly coerced into strings using +. Rationale: Each invocation of Symbol() produces a brand-new unique primitive identifier. Unless registered globally via Symbol.for(), two symbols with the same description are never equal (Symbol('id') !== Symbol('id')). Question 17 Which method retrieves a shared global Symbol from the global Symbol registry, creating it if it does not yet exist? A) Symbol.create('key') B) [CORRECT ANSWER] Symbol.for('key') C) Symbol.keyFor('key') D) Symbol.global('key') Rationale: Symbol.for(key) searches the runtime-wide global symbol registry for the given string key and returns the existing symbol if found, or creates and registers a new one otherwise. Question 18 What is the result of +'42px'? A) 42 B) [CORRECT ANSWER] NaN C) '42px' D) TypeError Rationale: The unary plus (+) operator attempts full numeric conversion equivalent to Number('42px'). Unlike parseInt('42px', 10) which stops at non-digits and returns 42, +'42px' fails to parse the entire string and returns NaN. Question 19 In JavaScript, which statement about variable declarations with var inside an if block is true? A) var is block-scoped to the if statement. B) [CORRECT ANSWER] var is function-scoped (or globally scoped if outside a function), leaking outside the if block. C) var cannot be redeclared in the same scope. D) var throws a ReferenceError if read before assignment. Rationale: var ignores block boundaries (if, for, while) and is hoisted to the top of its enclosing function or global execution context, initialized with undefined.

Question 20 What does console.log(1 < 2 < 3) and console.log(3 > 2 > 1) output respectively? A) true, true B) [CORRECT ANSWER] true, false C) false, true D) false, false Rationale: Relational operators associate left-to-right: 1 < 2 is true, and true < 3 coerces true to 1 (1 < 3 - > true). For 3 > 2 > 1, 3 > 2 is true, and true > 1 coerces true to 1 (1 > 1 - > false). Question 21 What is the value of x after executing: let x = 5; x ||= 10;? A) [CORRECT ANSWER] 5 B) 10 C) true D) undefined Rationale: The logical OR assignment operator (||=) only assigns the right-hand value if the left-hand variable is falsy. Because 5 is truthy, x remains 5. Question 22 Which operator checks whether a property exists anywhere in an object or its prototype chain? A) Object.hasOwn(obj, 'prop') B) [CORRECT ANSWER] 'prop' in obj C) obj.hasOwnProperty('prop') D) obj.prop !== undefined Rationale: The in operator returns true if the specified property exists either directly on the object or inherited along its prototype chain, whereas Object.hasOwn() checks only own enumerable/non- enumerable properties. Question 23 What happens when JSON.stringify({ a: undefined, b: Symbol('s'), c: () => {}, d: 10 }) is executed? A) It throws a TypeError due to unsupported types. B) [CORRECT ANSWER] Keys a, b, and c are omitted, producing '{"d":10}'. C) Keys a, b, and c are serialized as null. D) It serializes the function source code as a string. Rationale: When serializing an object, JSON.stringify() silently omits any property whose value is undefined, a Symbol, or a Function.

Question 28 Which expression safely accesses the first element of an array items that might be null or undefined? A) items.[0] B) [CORRECT ANSWER] items?.[0] C) items?[0] D) items->[0] Rationale: Optional chaining supports bracket notation for dynamic properties and array indices using the syntax obj?.[expr] (items?.[0]). Question 29 What is the result of Boolean('false') and Boolean(new String(''))? A) false, false B) true, false C) false, true D) [CORRECT ANSWER] true, true Rationale: Any non-empty string (including 'false' and '0') is truthy, and any object wrapper (even new String('')) is an object and therefore truthy. Question 30 What does the Comma Operator (let a = (1 + 2, 3 + 4);) assign to a? A) 3 B) [CORRECT ANSWER] 7 C) [3, 7] D) SyntaxError Rationale: The comma operator evaluates each of its operands from left to right and returns the value of the last operand (3 + 4 = 7). Question 31 Which statement about NaN is true according to IEEE 754 and ECMAScript? A) typeof NaN is 'undefined'. B) [CORRECT ANSWER] NaN is the only value in JavaScript that is not strictly equal (===) to itself. C) NaN === NaN evaluates to true. D) Math.max() returns NaN. Rationale: NaN is unordered under IEEE 754, making NaN === NaN and NaN == NaN both evaluate to false—the only value in JavaScript with this property.

Question 32 What is the output of console.log(2 ** 3 ** 2)? A) 64 B) [CORRECT ANSWER] 512 C) 12 D) SyntaxError Rationale: Unlike most binary arithmetic operators, the exponentiation operator (**) is right- associative. It evaluates 3 ** 2 first (9), and then 2 ** 9 (512). Question 33 When using switch (val), what comparison algorithm does JavaScript use to match case clauses? A) Abstract Equality (==) B) [CORRECT ANSWER] Strict Equality (===) C) SameValue (Object.is) D) String coercion comparison Rationale: switch statements compare the switch expression against each case clause using strict equality (===), so '1' will not match case 1:. Question 34 What happens if you try to delete a variable declared with let count = 1; using delete count in strict mode? A) count becomes undefined. B) [CORRECT ANSWER] It throws a SyntaxError at parse time. C) It returns false silently. D) It deletes the variable from block scope. Rationale: In strict mode ('use strict', ES modules, and classes), attempting to apply delete to an unqualified identifier (delete count) is an early SyntaxError. Question 35 Which expression converts any value v into its strict boolean equivalent without calling a constructor? A) new Boolean(v) B) [CORRECT ANSWER] !!v C) +v D) ~v Rationale: Double logical NOT (!!v) coerces any value to a primitive boolean (true or false), whereas new Boolean(v) creates a truthy wrapper object.

Question 40 What is the key difference between Function.prototype.call() and Function.prototype.apply()? A) call() invokes the function immediately; apply() returns a new bound function. B) [CORRECT ANSWER] call() accepts arguments as a comma-separated list, whereas apply() accepts arguments as an array or array-like object. C) apply() overrides arrow function this, whereas call() does not. D) call() works only in strict mode. Rationale: Both call(thisArg, arg1, arg2) and apply(thisArg, [arg1, arg2]) invoke the function immediately with an explicit this context; they differ only in how arguments are passed. Question 41 What does Function.prototype.bind(thisArg, arg1) return? A) The return value of executing the target function immediately. B) [CORRECT ANSWER] A new function with this permanently bound to thisArg and arg1 partially applied. C) undefined if thisArg is null. D) A shallow copy of thisArg. Rationale: bind() does not execute the function immediately; it returns a new exotic bound function whose this value is permanently locked to thisArg (unless called with new) and whose leading arguments can be pre-filled (partial application). Question 42 In strict mode, what is the value of this inside a standalone regular function call function show() { return this; } show();? A) window / globalThis B) [CORRECT ANSWER] undefined C) show D) {} Rationale: In strict mode, simple standalone function invocations do not default this to the global object; instead, this remains undefined. Question 43 Which statement accurately describes function hoisting in JavaScript? A) Function expressions (const f = function() {}) are hoisted with their body initialized. B) [CORRECT ANSWER] Function declarations (function f() {}) are hoisted completely with both name and implementation, allowing calls before the declaration line. C) Arrow functions are hoisted above import statements. D) Function hoisting only occurs in non-strict mode. Rationale: Function declarations are hoisted in their entirety during the creation phase of an execution context, whereas var/let/const function expressions follow variable hoisting rules.

Question 44 What is the value of fn.length for function fn(a, b = 2, c) {}? A) 3 B) 2 C) [CORRECT ANSWER] 1 D) 0 Rationale: A function's .length property counts the number of formal parameters before the first parameter with a default value (and excludes rest parameters). Here only a precedes b = 2, so fn.length is 1. Question 45 What is the output of: let x = 10; function foo() { console.log(x); } function bar() { let x = 20; foo(); } bar(); A) 20 B) [CORRECT ANSWER] 10 C) undefined D) ReferenceError Rationale: JavaScript uses lexical (static) scoping, not dynamic scoping. Because foo was defined in the outer scope where x = 10, calling foo inside bar resolves x to 10. Question 46 When are default parameter expressions evaluated in JavaScript (function add(a, b = getDefault()))? A) Once when the function is parsed. B) [CORRECT ANSWER] At call time, each time the function is invoked without an explicit argument (or with undefined) for that parameter. C) Only if null is passed as the argument. D) Before the function's outer scope is created. Rationale: Default parameter expressions are evaluated lazily at call time whenever the corresponding argument is omitted or explicitly undefined. Passing null does NOT trigger the default value.

Question 51. Consider the following code snippet: const obj = { value: 42, getValue: () => this.value }; What does obj.getValue() return when executed in an ES module (strict mode)? A) 42 B) [CORRECT ANSWER] TypeError: Cannot read properties of undefined (reading 'value') C) null D) ReferenceError: this is not defined Rationale: Arrow functions do not bind their own 'this'; they lexically inherit 'this' from the enclosing module scope. In ES modules, top-level 'this' is undefined, so accessing this.value throws a TypeError. Question 52. Which statement accurately differentiates Function.prototype.call(), Function.prototype.apply(), and Function.prototype.bind()? A) call() and apply() return a new bound function for later execution, whereas bind() invokes the function immediately. B) [CORRECT ANSWER] call() accepts arguments as a comma-separated list and invokes immediately; apply() accepts arguments as an array-like object and invokes immediately; bind() returns a new function with a permanently bound 'this' and optional preset arguments. C) apply() permanently mutates the original function's 'this' binding, whereas call() only applies temporarily. D) bind() can override the 'this' binding of an arrow function if passed null as the first argument. Rationale: Both call() and apply() execute the target function immediately (differing only in whether arguments are passed individually or as an array), whereas bind() creates and returns a new wrapped function without immediately invoking it. Question 53. What is the output of the following code? for (var i = 0; i < 3; i++) { setTimeout(() => console.log(i), 0); } A) 0, 1, 2 B) [CORRECT ANSWER] 3, 3, 3 C) undefined, undefined, undefined D) 0, 0, 0 Rationale: Because 'var' is function-scoped (or global-scoped here) rather than block-scoped, all three arrow function callbacks close over the exact same 'i' binding, which has incremented to 3 by the time the asynchronous timer callbacks run.

Question 54. Why does replacing 'var' with 'let' in a standard for-loop header (for (let i = 0; i < 3; i++)) resolve closure capture issues in asynchronous callbacks? A) let hoists each iteration variable into a separate global property. B) [CORRECT ANSWER] The JavaScript engine creates a fresh lexical environment binding for 'i' on each loop iteration, so each callback closes over its own distinct value. C) let forces setTimeout callbacks to execute synchronously before the next iteration begins. D) let converts primitive numbers into immutable wrapper objects. Rationale: Per the ECMAScript specification, a 'let' declaration in a for-loop head creates a new per-iteration lexical binding initialized with the previous iteration's value, allowing each closure to capture its own snapshot. Question 55. In JavaScript, what is a closure? A) A function that takes no parameters and returns undefined. B) [CORRECT ANSWER] A function bundled together with references to its surrounding lexical environment, retaining access to outer variables even after the outer function has returned. C) An Immediately Invoked Function Expression (IIFE) that automatically garbage-collects all variables upon completion. D) A private method declared using the # prefix inside an ES2022 class. Rationale: A closure is formed whenever an inner function maintains a live reference to variables in its outer lexical scope after the outer execution context has popped off the call stack. Question 56. Which feature distinguishes Rest Parameters (...args) from the legacy 'arguments' object inside a standard function? A) The 'arguments' object is a true Array instance with .map() and .filter(), while Rest Parameters are Array- like objects. B) [CORRECT ANSWER] Rest Parameters collect only trailing arguments not matched by named parameters into a genuine Array instance, and work inside arrow functions. C) Rest Parameters can appear in any position in the parameter list, including before named parameters. D) The 'arguments' object works identically in both regular functions and arrow functions. Rationale: Rest parameters produce a real Array containing remaining arguments and are supported in arrow functions (which lack their own 'arguments' binding), whereas 'arguments' is an Array-like object containing all passed arguments. Question 57. What happens when a function is invoked with the 'new' operator (e.g., new Person('Ada'))? A) [CORRECT ANSWER] A new empty object is created, linked to Person.prototype, bound as 'this' inside Person, and returned automatically unless the constructor explicitly returns a non-primitive object. B) Person is executed with 'this' set to the global object, and its return value is ignored. C) A shallow clone of the Person function itself is returned. D) Person.prototype is copied onto the global window object. Rationale: The 'new' operator creates a fresh instance whose [[Prototype]] points to Constructor.prototype, executes the constructor with 'this' referencing that instance, and returns the instance (unless another object is explicitly returned). Question 58. What is the output of the following default parameter evaluation? function calc(a = 10, b = a * 2) {

Question 62. What happens during the Creation Phase of a Function Execution Context before any line of the function body executes? A) All let and const variables are initialized to undefined. B) [CORRECT ANSWER] Function declarations are hoisted with their definitions, 'var' declarations are hoisted and initialized to undefined, and let/const declarations are hoisted into the Temporal Dead Zone (TDZ). C) All asynchronous callbacks in the function are executed immediately. D) The function's return value is precomputed. Rationale: During the Creation Phase, the lexical environment registers function declarations completely, initializes 'var' bindings to undefined, and leaves 'let'/'const' bindings uninitialized in the TDZ until evaluation reaches their declaration. Question 63. If a function bound with fn.bind(objA) is subsequently invoked via boundFn.call(objB), which object does 'this' refer to inside the function? A) objB B) [CORRECT ANSWER] objA C) undefined D) The global object Rationale: Once a function is bound via Function.prototype.bind(), its 'this' binding is permanent and cannot be overridden by subsequent call(), apply(), or bind() calls (only 'new' can override hard binding). Question 64. What is the primary architectural benefit of an Immediately Invoked Function Expression (IIFE) in legacy non-module scripts? A) It enables top-level await in ES5 browsers. B) [CORRECT ANSWER] It creates an isolated lexical scope that prevents temporary helper variables from polluting the global namespace. C) It forces the JavaScript engine to run the code on a background Web Worker thread. D) It prevents garbage collection of local variables. Rationale: Before ES6 block scoping (let/const) and ES modules, IIFEs encapsulated private state and setup logic inside a function scope so globals were not overwritten. Question 65. What does a generator function (function* gen()) return when invoked directly? A) The value following the first yield keyword. B) [CORRECT ANSWER] A Generator object conforming to both the Iterable and Iterator protocols, without executing the function body until .next() is called. C) A Promise that resolves when all yield statements complete. D) An Array of all yielded values. Rationale: Calling a generator function returns a suspended Generator object. Execution pauses at each 'yield' expression and resumes only when .next() is invoked.

Question 66. In a generator function, what does calling iterator.next(value) with an argument accomplish? A) It overwrites the generator's function parameters. B) [CORRECT ANSWER] It passes 'value' into the generator as the result of the currently suspended 'yield' expression. C) It resets the generator back to its initial state. D) It terminates the generator immediately. Rationale: Two-way communication with generators allows iterator.next(val) to inject 'val' as the evaluated outcome of the paused 'yield' expression inside the generator body. Question 67. Which technique optimizes repeated expensive pure function calls by caching results keyed by input arguments inside a closure? A) Debouncing B) [CORRECT ANSWER] Memoization C) Throttling D) Trampolining Rationale: Memoization wraps a pure function with a private cache (e.g., a Map) via a closure, returning cached results immediately when identical arguments are supplied again. Question 68. What is the difference between debouncing and throttling a high-frequency event handler (such as window scroll or keyup)? A) Debouncing executes immediately on every event; throttling waits until events stop. B) [CORRECT ANSWER] Debouncing delays execution until a quiet period has elapsed since the last event; throttling guarantees execution at most once per fixed time interval. C) Debouncing only works with Promises; throttling only works with setInterval. D) Both techniques cancel all DOM event bubbling. Rationale: Debouncing collapses bursts of events into a single call after inactivity (ideal for search-as-you-type), whereas throttling enforces a steady maximum execution rate during continuous events. Question 69. In strict mode ('use strict'), what is the value of 'this' inside a standalone function invoked directly as myFunc() without an explicit receiver object? A) window (or globalThis) B) [CORRECT ANSWER] undefined C) myFunc D) Object.prototype Rationale: In strict mode, default 'this' binding does not fall back to the global object; instead, 'this' remains undefined when a function is called without a receiver.