In JavaScript, a variable can be declared after it has been used.
In other words; a variable can be used before it has been declared.
JavaScript only hoists declarations, not initializations.
Interviews4 answers
What is Function Hoisting ?
4 Answers
Bidyasagar MishraPosted Aug 1, 2019, 9:43 PM EDT
you are using function before declaring it.
Naveen BishtPosted Feb 15, 2017, 10:11 PM EST
console.log("From calling "+myFunction());
function myFunction()
{ console.log("From function "+ " Function Hoisting !!!");
return "Function Hoisting !!!"; }
Output - From function Function Hoisting !!! From calling Function Hoisting !!!
So, you can call a function (myFunction()) even before declaring it.
This is called Function Hoisting in JavaScript.
Atul SharmaPosted Feb 10, 2017, 6:33 AM EST
console.log("From calling "+myFunction());
function myFunction()
{
console.log("From function "+ " Function Hoisting !!!");
return "Function Hoisting !!!";
}
Output -
From function Function Hoisting !!!
From calling Function Hoisting !!!
So, you can call a function (myFunction()) even before declaring it. This is called Function Hoisting in JavaScript.
Atul SharmaPosted Jan 10, 2017, 5:42 AM EST


