Detached method vs explicit call
Use strict-mode receiver rules. What does each invocation read?
Code Snippet
"use strict";
const profile = { name: "Ada", read() { return this?.name; } };
const read = profile.read;
const other = { name: "Lin", read };
console.log(profile.read(), read(), other.read());
console.log(read.call({ name: "Kai" }));Expected Output & Explanation
Ada undefined Lin
Kai The receiver is determined by the call site. The plain call gives undefined in strict mode, optional chaining returns undefined, and call supplies Kai’s object explicitly.
Module Context & References
JavaScript · Language output drills Trace closures, receivers, prototypes, coercion and array edge cases
Personal Notes · Markdown