Programming
Objective Assessment Review
(Questions & Solutions)
2025
©2025
,1. Question 1
Consider the following code snippet that demonstrates a closure:
```javascript
function createIncrementer() {
let count = 0;
return function() {
count += 1;
return count;
};
}
const inc1 = createIncrementer();
console.log(inc1()); // ?
console.log(inc1()); // ?
```
What is the expected output of the two `console.log` statements?
- A. 0 and 0
- B. 1 and 2
- C. 1 and 1
- D. 2 and 3
ANS: B
Rationale: The inner function forms a closure over the variable
`count`. Each time `inc1()` is invoked, it increments `count` from its
previous value (starting at 0), so the outputs are 1 and then 2.
2. Question 2
In advanced JavaScript, when using an arrow function within an object
method, what is a key difference compared to traditional function
expressions?
- A. Arrow functions bind `this` lexically.
- B. Arrow functions create a new `this` context.
- C. Arrow functions are always anonymous.
©2025
, - D. Arrow functions cannot be assigned to variables.
ANS: A
Rationale: Arrow functions do not have their own `this` binding;
instead, they inherit the `this` value from the surrounding (lexical) scope,
which is crucial in many advanced patterns.
3. Question 3
Which of the following best describes the behavior of JavaScript’s event
loop when processing asynchronous operations?
- A. It processes all macrotasks first, then microtasks.
- B. It handles the microtask queue before processing the next
macrotask.
- C. It executes asynchronous callbacks immediately as they are
encountered.
- D. It blocks execution until all asynchronous tasks complete.
ANS: B
Rationale: The event loop empties the call stack, then processes the
microtask queue (including promise resolutions) before moving on to the
next macrotask, ensuring timely and ordered execution.
4. Question 4
Examine the following Promise chain:
```javascript
Promise.resolve(42)
.then(x => { console.log(x); return x + 1; })
.then(x => { throw new Error('fail'); })
.catch(e => { console.log(e.message); return 100; })
.then(x => { console.log(x); });
```
What is the output produced by this code?
- A. 42, "fail", 43
- B. 42, "fail", 100
- C. 42, 100, "fail"
- D. 42, 43, "fail"
ANS: B
©2025
, Rationale: The first `.then` logs 42 and returns 43. The next `.then`
throws an error, triggering the `.catch`, which logs "fail" and returns 100.
The final `.then` then logs 100.
5. Question 5
Which JavaScript feature makes an object iterable using the `for...of`
loop?
- A. `Symbol.iterator`
- B. `Object.keys`
- C. `Array.prototype.forEach`
- D. `Proxy` traps
ANS: A
Rationale: Defining a method on an object with the key
`Symbol.iterator` allows that object to be iterated over using `for...of`.
6. Question 6
Regarding JavaScript’s prototype inheritance, which statement is
correct?
- A. Every function in JavaScript automatically receives a `prototype`
property used for inheritance.
- B. Prototype inheritance has been entirely replaced by ES6 classes.
- C. Only objects created with the `new` operator have prototypes.
- D. Prototypes exist solely for arrays.
ANS: A
Rationale: Every function has a `prototype` property, and the
prototype chain enables objects to inherit properties and methods from
one another.
7. Question 7
What is the main advantage of using `async/await` over traditional
promise chaining?
- A. It eliminates the need for error handling.
- B. It makes asynchronous code appear and behave much like
synchronous code, enhancing readability.
- C. It automatically executes asynchronous tasks in parallel.
©2025