Skip to content

Instantly share code, notes, and snippets.

@VishalVishwakarma
Last active January 22, 2022 06:39
Show Gist options
  • Save VishalVishwakarma/70151296bc0004da0df768fe5edcdbf7 to your computer and use it in GitHub Desktop.
Save VishalVishwakarma/70151296bc0004da0df768fe5edcdbf7 to your computer and use it in GitHub Desktop.
Global variables in Javascript across multiple files
<!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>
var globalvar = 'Hello Global Variable Called!';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment