LearnFrenzy
Sign in Take a free test

JavaScript Basics · Predict the Output · Question 13

this in a non-strict function Answer, explanation & discussion

  • Output
  • Hard
  • 0 comments
  • Answer explained
  • Moderated community
Question 13 Back to Exercise

What does the following JavaScript code print (console output, as in Node.js)?

main.js
function kind() {
  return typeof this;
}
console.log(kind(), this === undefined);
  • A undefined true
  • B object true
  • C object false Correct
  • D function false
Correct Answer: Option C

Non-strict plain calls receive the global object as this, so typeof this is "object". At the top level of a Node.js script this is module.exports ({}), which is not undefined either.

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!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links