{"@context":"https://schema.org","@type":"BlogPosting","author":{"@type":"Person","name":"Pawl"},"dateModified":"2012-06-05T15:14:00+00:00","datePublished":"2012-06-05T15:14:00+00:00","description":"Problem: I had two different <script> (javascript) sections, and I was unable to pass a variable from one set of <script> tags to the other.Turns out it doesn’t have anything to do with the script tags, and I just needed to learn a bit more about scope in Javascript. Apparently global variables are a common thing (maybe still not a good practice?) and as long as a variable is used outside of a function.. You’ll be able to access the variable anywhere on the page.Solution: Take the variable outside of the function.","headline":"Global Variables In Javascript","mainEntityOfPage":{"@type":"WebPage","@id":"https://www.paulsprogrammingnotes.com/2012/06/global-variables-in-javascript.html"},"url":"https://www.paulsprogrammingnotes.com/2012/06/global-variables-in-javascript.html"}

Paul's Programming Notes     Archive     Feed     Github

Global Variables In Javascript

Problem: I had two different <script> (javascript) sections, and I was unable to pass a variable from one set of <script> tags to the other.

Turns out it doesn't have anything to do with the script tags, and I just needed to learn a bit more about scope in Javascript. Apparently global variables are a common thing (maybe still not a good practice?) and as long as a variable is used outside of a function.. You'll be able to access the variable anywhere on the page.

Solution: Take the variable outside of the function.