This was the statement I came across which was written by Akshay Saini Sir
I had lots of questions in my mind and this series cleared all my doubts!!
So let’s get started!!!
What is hoisting?
Hoisting is the ability to access variables and functions even before initializing them.
It will give output as undefined because x is accessed before it is initialized.
When we get Reference Error as Not Defined?
Output is a Reference Error showing x is not defined because x is not present in the code and still you are trying to access the value.
Let us quickly revise undefined and not defined in a single piece of code.
var a= 7;
undefined //Because value is accessed before initializing a
7//now a has assigned a value 7
Reference Error x is not defined//Because the value of x is not defined anywhere in the memory space.
It also creates a “Window”.
So what is a Window?
Introduction to this keyword
Whenever you create an execution context, a “this” is also created along with it. This is applicable for functional and global execution contexts. At a global level, “this” points to the global object “window” in the case of the browser.
var a= 10
In the global space window. a , this. a and a refer to the same value.
Please share your feedback on this article and if you liked it share it will all your friends!!
In the upcoming article, I will be explaining the scope chain, scope, and lexical environment, temporal dead zone, and difference between syntax error, reference error, and type error.
Till then happy learning!!!