I wonder why the function can see the variables "a" and "b" even though they are declared and defined outside of the function scope?
function whichOneGreater() {
a > b ? console.log("a: ", a) : console.log("b: ", b);
}
var a = 3/4;
var b = 4/9;
whichOneGreater()
if I change the variable name from a to c
function whichOneGreater() {
a > b ? console.log("a: ", a) : console.log("b: ", b);
}
var c = 3/4;
var b = 4/9;
whichOneGreater()
then the error happens
script.js:2 Uncaught ReferenceError: a is not defined
at whichOneGreater (script.js:2)
at script.js:8
Edit: I found an article that answers my question well here