Sign in
Log inSign up

`this` keyword in javascript

Default profile photo
Anonymous
·Mar 28, 2018
function a(){
    this.kk="ghf";
}
console.log(kk);
a();

Here I am getting error as "kk is not defined",but if we follow the concept then we can say that this keyword in the above case is creating new global variable kk and while creation phase it should save the variable kk in global execution context.so the value of kk in above case should be undefined instead of error message. As per my knowledge all global variable present in global execution context ,so "kk" should be there. Below is the example for above said hypothesis :

console.log(a)
var a=8;
// output will be undefined
Hassle-free blogging platform that developers and teams love.
  • Docs by Hashnode
    New
  • Blogs
  • AI Markdown Editor
  • GraphQL APIs
  • Open source Starter-kit

© Hashnode 2024 — LinearBytes Inc.

Privacy PolicyTermsCode of Conduct