#10 JavaScript Challenge : What Will this Keyword Output? Test Your Knowledge! #shorts #MRCODER

preview_player
Показать описание
JavaScript Challenge #10: What Will this Keyword Output? Test Your Knowledge!

In this JavaScript Challenge #10, we dive into a question about the `this` keyword. Test your understanding of how `this` behaves in different contexts with this tricky problem!

🔍 **What You'll Learn:**
- How the `this` keyword works in JavaScript
- The impact of losing context in function assignment
- Common pitfalls and best practices for handling `this`

📚 **Related Videos:**
- [JavaScript Challenge #9: Array Splice Problem]
- [JavaScript Challenge #8: Understanding Closures]

👍 **Like, Subscribe, and Hit the Bell Icon for More JavaScript Challenges and Tutorials!**

#JavaScript #CodingChallenge #JavaScriptChallenge #WebDevelopment #Programming #MR CODER #javascripttips

Hashtags
#JavaScript
#CodingChallenge
#JavaScriptChallenge
#WebDevelopment
#Programming
#MR CODER
#JavaScriptTips
Tags
JavaScript, Coding Challenge, JavaScript Challenge, Web Development, Programming, JavaScript Tips, MR CODER, JavaScript Functions, Learn JavaScript, JavaScript this Keyword
Рекомендации по теме
Комментарии
Автор

Correct Answer: B) undefined

Explanation:
The this keyword refers to the object that the function is a method of when it is invoked.
In the getName method, this.name refers to the name property of the person object when called as person.getName().
When const getPersonName = person.getName; is executed, getName is assigned to the variable getPersonName, but it loses its context (i.e., it is no longer bound to the person object).
Calling getPersonName() will now execute the function in the global context (or undefined in strict mode), and since the global object does not have a name property, this.name returns undefined.

MRCODER_YT