JavaScript Hoisting

The mechanism of using variables and functions before their declarations by moving their declarations to the top of the code is called hoisting in Javascript.

Example:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<script>
document.write(mul(2,5,6));
function mul(a,b,c)
{
return a*b*c;
}
</script>
</body>
</html>
<!DOCTYPE html> <html> <head> </head> <body> <script> document.write(mul(2,5,6)); function mul(a,b,c) { return a*b*c; } </script> </body> </html>
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<script>
document.write(mul(2,5,6));
function mul(a,b,c)
{
return a*b*c;
}
</script>
</body>
</html>