I'd like to call a variable, lets say var cow; which is placed in the function function farm() in the function function milk().
<script type="text/javascript">
var cow
function farm() {
cow = Math.Random;
}
function milk(){
// call/return value of cow
}
</script>
Check out this link: GLOBAL VARIABLES IN JAVASCRIPT by Snook
.
Now if you see the last code carefully, and test it...it actually doesn't work, but I want something similar to work. You can check the code below...
var myValue;
function setValue()
{
myValue = "test";
}
function getValue()
{
alert(window.myValue); // yup, it's "test" (original) ---> (after testing) No its "undefined"
}
cowwill be global. However, you're probably looking forMath.random()and notMath.Random(which is undeclared and thus undefined).. See my answer for more details.