When I define the variable outside of a func, it returns undefined. I couldn't find out the reason why.
document.write(myFunc());
var x = 1;
function myFunc() {
return x;
}
output: undefined
However if I define variable inside the func, it works.
document.write(myFunc());
function myFunc() {
var x = 1;
return x;
}