Question 3
Back to Exercise
What does the following JavaScript code print (console output, as in Node.js)?
const site = {
name: "LF",
regular() { return this.name; },
arrow: () => typeof this.name,
};
console.log(site.regular(), site.arrow());
- A LF string
- B undefined undefined
- C LF undefined Correct
- D LF LF
Correct Answer: Option C
regular() gets this = site. The arrow takes this from the top level of the file – in a Node.js script that is module.exports, an empty object – so this.name is undefined.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!