How To Use Scope Using JavaScript?


Share:
Published By: Admin, Published On: Nov 17, 2021, Category: Javascript


Hello Friends,

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

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

Example : 1
<!DOCTYPE html>   
<html>  
    <head>
        <title>How To Use Scope Using JavaScript? - MyWebtuts.com</title>   
    </head>  
    <body> 
        <h3>How To Use Scope Using JavaScript? - MyWebtuts.com</h3> 
        <script>  
            var a1 = 25;     
                
            function example() {      
                var a1 = 40;     
                document.write("Inside Example Function = " + a1);     
            }     
            document.write("Outside Example Function = "  + a1);    
            document.write("<br>");  
            example();   
        </script>  
    </body>  
</html>  
Output :
Outside Example Function = 25
Inside Example Function = 40
Example : 2
<!DOCTYPE html>   
<html>  
    <head>
        <title>How To Use Scope Using JavaScript? - MyWebtuts.com</title>   
    </head>  
    <body> 
        <h3>How To Use Scope Using JavaScript? - MyWebtuts.com</h3> 
        <script>  
            function a1() {      
                b1 = 50;     
                document.write("Inside Example Function = " + b1);     
            }     
            a1();
               
            document.write("<br>");  
            document.write("Outside Example Function = "  + b1);    
        </script>  
    </body>  
</html>    
Output :
Inside Example Function = 50
Outside Example Function = 50

It will help you...

Share: