Skip to content
Menu
  • Company
    • About Us
    • Store
    • Contact Us
  • E – Seva Kendra Common Service Center
  • Products And Services
  • Join our Social Network
  • Search
  • Company
    • About Us
    • Store
    • Contact Us
  • E – Seva Kendra Common Service Center
  • Products And Services
  • Join our Social Network

Instarr Softwares Ichalkaranji

Good sales people are first to be hired and last to be fired - Mr Shiv Khera

Javascript Global Variable

JavaScript Global Variable:-

1.Global  Variable:-

In contrast, global variables are variables that are defined outside of functions. These variables have global scope, so they can be used by any function without passing them to the function as parameters.

Example:-
!DOCTYPE html>
<html>
 
<body>
    <center>
        <h1 style="color:green;">GeeksforGeeks</h1>
 
        <p>Outside myfunction() petName is not defined.</p>
 
        <p id="Geeks"></p>
 
        <p id="geeks"></p>
 
        <script>
            myfunction();
 
            function myfunction() {
                var petName = "Sizzer"; // local variabl
                document.getElementById("Geeks").innerHTML =
                    typeof petName + " " + petName;
            }
 
            document.getElementById("geeks").innerHTML =
                typeof petName;
        </script>
  </center>
 
</body>
 
</html>
Output:-

2. Local  Variable:-

When you use JavaScript, local variables are variables that are defined within functions. They have local scope, which means that they can only be used within the functions that define them.
Example:-
<!DOCTYPE html>
<html>
 
<body>
    <center>
        <h1 style="color:green;">GeeksforGeeks</h1>
 
        <p>A GLOBAL variable can be accessed from 
                            any script or function.</p>
 
        <p id="geeks"></p>
        <p id="Geeks"></p>
        <script>
            var petName = "Rocky";//global variable
            myFunction();
 
            function myFunction() {
                document.getElementById("geeks").innerHTML =
                  typeof petName + "- " + "My pet name is " + petName;
            }
 
            document.getElementById("Geeks").innerHTML =
               typeof petName + "- " + "My pet name is " + petName;
        </script>
  </center>
 
</body>
 
</html>
Output:-
  • Web Development Course HTML | CSS | Javascript
  • Mysql Database Course
  • PHPmyadmin Course
  • PHP Coding Course
  • Image OCR to Text
  • Solutions to Problems
  • New Instarr Email yourname.instarr@gmail.com
  • Sign Up to Trello for your daily work assignments
  • Keep Open Whatsapp in PC
  • Install XAMPP to Linux
  • Create Gmail Email Templates for Marketing
  • PDF Tools
  • Files Shared instarrcom@gmail.com
  • Learning Center

Copyright © 2025 Instarr Softwares Ichalkaranji. All Rights Reserved.

Codilight Theme by FameThemes