Javascript create global variable

linkaiyi
Follow

Create Javascript global variable

Yes, as the others have said, you can use var at global scope (outside of all functions) to declare a global variable:

<script>
var yourGlobalVariable;
function foo() {
    // ...
}
</script>

// Alternately, you can assign to a property on window:

<script>
function foo() {
    window.yourGlobalVariable = ...;
}
</script>
Object has 0 attachments

Was this article helpful?

This article is viewed 18 times!

Recent Viewed Articles

0 Comments

Leave a Comment

Support