
Hoisting
Use Function Before Declaration
31 October, 2022
0
0
0
Contributors
Javascript pre-assumes that the declaration is on the top of current scope.
Let's say if we have defined a function in the bottom of our scope of script or function, even javascript interprter runs line by line , everyone can use this function before declaration .
But keep in mind we will declare it later after using it , otherwise it will never work
Output
This will print hello , no matter you decalre it before calling or after calling.
var
Output
In short , we can say Hoisting is a behaviour which moves the declarations on the top while interpreting its code.
Arrow functions are not hoisted.
Above code will return ReferenceError
Do it yourself with
var keyword
and arrow functions
. Also comment down if I have committed any mistake. Let's connect on my socials -- Always Open for new opportunities , if I am free :P