Code Snippet
Global Variables
Declare variable outside of the function...
var oneVariable;
function setVariable(){
oneVariable = "Variable set from within a function!";
}
function getVariable(){
alert(oneVariable); // Outputs "Variable set from within a function!"
}
Or... attach it to the window object
function setValue() {
window.myValue = "test";
}
function getValue() {
alert(window.myValue); // "test" (assuming setValue has run)
}
don’t even need to specify “var” when you are declaring a global.
It’s a good practice use the “var” keyword.
It’s bad practice to declare globals…
DigWP
A book and blog co-authored by Jeff Starr and myself about the World's most popular publishing platform.
Quotes on Design
Design, like Art, can be an elusive word to define and an awfully fun thing to have opinions about.
HTML-Ipsum
One-click copy to clipboard access to Lorem Ipsum text that comes wrapped in a variety of HTML.
Bookshelf
Hey Chris, what books do you recommend? These, young fertile mind, these.