DEV Community

Mahin Tazuar
Mahin Tazuar

Posted on • Updated on

Some fun with the 'this' keyword in javascript.

Today we are simply talking about simple and tricky things in javascript, which is called this keyword.' this' keyword is relative with the object. And what is the value of the 'this' keyword, it depend on where is called. Inside an object method, it returns this object. But remember only working within the object method not any object property. otherwise, it is not inside any object its return window object or undefined.If we are use it in a strick mode in a function its return undefine.Arrow function can not working with this keyword.

example 1: 
console.log(this) // this is return window object
example 2: 
function show(){
console.log(this) 
}
example 3:
const data = {
user: 'David',
age: 23,
doAction:function(){
console.log(this.user) // 'David'
}}
data.doAction();
Enter fullscreen mode Exit fullscreen mode

Object.create(person); This is help to you for understand more
support : thapa technical

Top comments (0)