Last active
January 22, 2022 06:39
-
-
Save VishalVishwakarma/70151296bc0004da0df768fe5edcdbf7 to your computer and use it in GitHub Desktop.
Global variables in Javascript across multiple files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<body> | |
<h1>Example of JS Global Variable</h1> | |
<p>Using variable from one JS file to another.</p> | |
<p>Open the console to view the output.</p> | |
<p id="demo"> | |
<script type="text/javascript"> | |
var globalvar = false; | |
</script> | |
<script type='text/javascript' src='script.js'></script> | |
<script> | |
console.log(globalvar); | |
document.getElementById('demo').innerHTML = globalvar; | |
</script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var globalvar = 'Hello Global Variable Called!'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment