I am new to JavaScript and wanted to ask the following: I have two simple functions, and I was wondering if there is a way to pass the value of a variable from one function to another. I know that I can just move it outside the function that will be used in other functions, but I just need to know how I can have one local variable and manipulate it in the second function. Is this possible and how?
Here is the code:
window.onload = function show(){ var x = 3; } function trig(){ alert(x); } trig();
The question is: how do I access the variable x
(declared in the show
function) from my second trig
function?
source share