Understanding <code>this</code> in Global Scope
📖 Scenario: Imagine you are learning how JavaScript handles the keyword this when used outside of any function or object. This is important because this behaves differently depending on where you use it.
🎯 Goal: You will write code to see what this refers to in the global scope and print its value.
📋 What You'll Learn
Create a variable called
globalThisValue and assign it the value of this in the global scope.Create a variable called
isGlobalWindow that checks if globalThisValue is the same as the global window object.Print the value of
globalThisValue.Print the value of
isGlobalWindow.💡 Why This Matters
🌍 Real World
Understanding <code>this</code> in the global scope helps you know what object your code is referring to when you use <code>this</code> outside of functions or objects.
💼 Career
Many JavaScript jobs require understanding how <code>this</code> works to avoid bugs and write clear code, especially when working with browser APIs or frameworks.
Progress0 / 4 steps