Answers for "this.this in javascript"

11

what is this in javascript

// this = current execution context (window in browser, global in nodejs)
console.log(this) // window object

function foo () {
 console.log(this); // object calling this function
}

foo(); // undefined

o={ foo }
o.foo(); // 'o' object logged
Posted by: Guest on June-21-2021
-1

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);
Posted by: Guest on January-17-2022

Code answers related to "Javascript"

Browse Popular Code Answers by Language