The above codes will work fine and the output will be undefined, internally this will behave as:
If we talk about the variables and constants, keyword var is hoisted and let and const does not allow hoisting.
Hoisting, inside the function:When we use any variable in the function scope, the variable is hoisted only to the top of the function. Outside the function scope, it will throw an error "Uncaught ReferenceError: X is not defined", For example:
Examples with let and const:
Here is an issue with function hoisting:
If you are using an function expression it will throw an error, because only declarations are hoisted.
If you use var in the above codes, then you will get another error "Uncaught TypeError: test is not a function".
Strongly Recommended Books For You:
For Other Countries (United States, United Kingdom, Spain, Italy, Germany, France, Canada, etc)
If you found this article is helpful, then please share this article's link to your friends to whom this is required, you can share this to your technical social media groups also. You can follow us on our social media page for more updates and latest article updates.
To read more about the technologies, Please subscribe us, You'll get the monthly newsletter having all the published article of the last month.