# What is THIS in JavaScript?
> In most cases, the value of `this` is determined by how a function is called (runtime binding).
| Usage (Context) | Refers to |
| ---------------------------- | ----------------------------------- |
| In a Method | Owner Object (Which invoked method) |
| Alone | Global Object |
| In a function (Default Mode) | Global Object |
| In a function (Strict Mode) | undefined |
| In an event | The element that received the event |
## In the Browser & Node.js
In JavaScript, the context of **THIS** differs based on how you call, and whether it’s been executed in strict mode or non-strict mode.
``` javascript
function foo() {
return this;
}
function foo2() {
'use strict';
return this;
}
console.log(foo2() === undefined); // true
// In the browser:
console.log(foo() === window); // true
// In Node.js:
console.log(foo() === globalThis); // true
```
```javascript
var a = {
value: 1,
getVal: () => this.value
}
var b = {
value: 2,
getVal: function () {
return this.value
}
}
var value = 0;
console.log(a.getVal()); // 0
console.log(b.getVal()); // 2
var c = a.getVal;
var d = b.getVal;
console.log(c()); // 0
console.log(d()); // 0
```
## References
1. [this - JavaScript | MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this)
2. [What is THIS in JavaScript? in 100 seconds - Fireship](https://www.youtube.com/watch?v=YOlr79NaAtQ)
3. [What Is ‘This’ Keyword in JavaScript ?and How It Behaves. | by Johnson Tito | The Startup | Jul, 2020 | Medium](https://medium.com/swlh/what-is-this-keyword-in-javascript-and-how-it-behaves-4929689bd114)
4. [What is THIS keyword in JavaScript and How to use it with Examples?](https://www.toolsqa.com/javascript/this-keyword-in-javascript/)
5. [淺談 JavaScript 頭號難題 this:絕對不完整,但保證好懂](https://blog.techbridge.cc/2019/02/23/javascript-this/)
###### tags: `JavaScript`