My FeedDiscussionsHeadless CMS
New
Sign in
Log inSign up
Learn more about Hashnode Headless CMSHashnode Headless CMS
Collaborate seamlessly with Hashnode Headless CMS for Enterprise.
Upgrade ✨Learn more

`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