How To Use Hoisting In JavaScript?

Nov 16, 2021 . Admin



Hello Friends,

Now let's see example of how to use hoisting example.We will check how to use hoisting. This is a short guide on use hoisting in javascript. Here you will learn how to use javascript hoisting. Let's get started with how to use hoisting in javascript.

Here i will give you many example how to use hoisting using javascript.

Example : 1
<!DOCTYPE html>  
<html>  
    <head>
        <title>How To Use Hoisting In JavaScript? - MyWebtuts.com</title>  
    </head>  
    <body> 
        <h3>How To Use Hoisting In JavaScript? - MyWebtuts.com</h3> 
        <script>  
            let a1;          
            a1 = 199;      
            document.write(a1); 
        </script>  
    </body>  
</html>  
Output :
159
Example : 2
<!DOCTYPE html>  
<html> 
    <head>
        <title>How To Use Hoisting In JavaScript? - MyWebtuts.com</title>
    </head> 
    <body> 
        <h3>How To Use Hoisting In JavaScript? - MyWebtuts.com</h3> 
        <script>

            function codeHoist(){   
                a1 = 25;   
                b1 = 68;
            }   
            codeHoist();

            function fun(){  
                console.log(a1);  
                console.log(b1);  
            } 
            fun(); 
        </script>  
    </body>  
</html>  
Output :
25
68

It will help you...

#Javascript