this keyword in javscript
const user = {
name: 'Mike';
call() {
console.log(this);
}
}
user.call();
// ⚙️ Output: {name: 'Mike, call: f}
this keyword in javscript
const user = {
name: 'Mike';
call() {
console.log(this);
}
}
user.call();
// ⚙️ Output: {name: 'Mike, call: f}
this keyword in javascript
// this keyword
// This keyword belongs to the object it belongs to
// (1).Alone, this refers to the global object.
// (2).In a regular function,this refers to the global object.
// (3).In a method, this refers to the owner object.
// 1
console.log(this);
// 2
function abc() {
console.log(this);
}
abc();
// 3
const obj = {
name: "Abhishek",
no: 1,
sum: function (a, b) {
console.log("hello sum", a + b);
console.log("this:::", this);
console.log("this name:::", this.name);
},
};
obj.sum(4, 3);
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us