JavaScript keyword usage is explored in this episode of Namaste JavaScript Season 2. Join us for an easy-to-follow discussion on using keywords in JavaScript.

“Understanding the ‘this’ keyword in JavaScript is like peeling an onion. It’s a wild ride, but once you get it, everything falls into place. Whether it’s global or inside a function, knowing how ‘this’ behaves is crucial. And don’t even get me started on arrow functions! They have their own rules and a whole different vibe. Remember, ‘this’ can be a real showstopper in interviews, so dive into call, apply, and bind. And when it comes to DOM elements, ‘this’ becomes cooler than the other side of the pillow. So, buckle up and let’s unravel the mysteries of ‘this’ in JavaScript! πŸŽ‰”

Key Takeaways πŸ“Œ

  • The ‘this’ keyword behaves differently based on different circumstances. Understanding its behavior is crucial in JavaScript.
  • The value of the ‘this’ keyword can vary in different operational modes, such as strict mode and non-strict mode.
  • The value of the ‘this’ keyword depends on how a function is called, making it essential to grasp its binding during runtime.

Global Space vs. Functional Space 🌐

In JavaScript, the ‘this’ keyword represents the global object, which can differ based on where the JavaScript code is running. For instance, the ‘this’ keyword inside a function can have a different value depending on the operational mode being used. If the code is running in strict mode, the value of ‘this’ is different compared to non-strict mode. Here’s a table to help illustrate this concept:

Operational ModeValue of ‘this’
Strict ModeDepends on call
Non-Strict ModeGlobal Object

Understanding ‘this’ Substitution πŸ”€

In JavaScript, ‘this’ substitution occurs when the value of the ‘this’ keyword is replaced by ‘undefined’ or ‘null’. The global object then takes the place of the ‘this’ keyword. Let’s explore this through an example:

"If ‘this’ is undefined or null, the value of the ‘this’ keyword is replaced by the global object."


The Contextual Binding of ‘this’ and Function Value 🎯

The value of the ‘this’ keyword inside a function depends on how the function is called. Its value is bound to the calling reference, which can result in ‘undefined’ if not explicitly set. When dealing with different functions, knowing how value assignment occurs is crucial. Here’s a table to summarize the binding of ‘this’ based on function calls:

Function CallValue of ‘this’
Normal functionWindow Object
Arrow functionLexical Context

Call, Apply, and Bind Methods πŸ’‘

Understanding the ‘call’, ‘apply’, and ‘bind’ methods in JavaScript is essential for utilizing the ‘this’ keyword effectively. Each method has its unique purpose in managing the context of the ‘this’ keyword within functions. It’s important to differentiate when to use ‘call’, ‘apply’, or ‘bind’, as they have distinct functionalities and implications on the ‘this’ binding.


Enclosing Lexical Context in Arrow Functions πŸ”„

Arrow functions in JavaScript have their lexical context, which differs from regular functions. The value of ‘this’ in arrow functions is based on the enclosing lexical context, rather than the specific calling reference. This concept can be quite complex to grasp, so here’s a list of key points to remember:

  • Arrow functions retain the value of ‘this’ from their enclosing lexical context.
  • Understanding where the function is present in the code is crucial for comprehending its behavior.
  • The lexical context of arrow functions determines the value of ‘this’.

Conclusion 🌟

The ‘this’ keyword in JavaScript is a fundamental concept that impacts the behavior and functionality of functions and methods. Understanding how ‘this’ behaves in different contexts and modes is crucial for mastering JavaScript development.


By diving deep into the intricacies of the ‘this’ keyword, JavaScript developers can enhance their understanding and effectively utilize it in their code. Remember to watch the associated video for a more in-depth explanation of these concepts. Happy coding! πŸš€

About the Author

About the Channel:

Share the Post:
en_GBEN_GB