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".
Support our IDKBlogs team
Creating quality content takes time and resources, and we are committed to providing value to our
If you find my articles helpful or informative, please consider supporting us financially.
Any amount (10, 20, 50, 100, ....), no matter how small, will help us continue to produce high-quality content.
Thank you for your support!
I appreciate you taking the time to read this article. The more that you read, the more things you will know. The more that you learn, the more places you'll go.
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.