Global Variables

0
0

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)
}
  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.