In JavaScript the statement var
declares a global variable?!
So why
function myFunction(){
let var1 = varG
console.log(var1)
}
function myOtherFunction(){
var varG = document.all
myFunction()
}
myOtherFunction()
This displays the following error:
Uncaught ReferenceError: varG is not defined
This also happens if myOtherFunction
is after myFunction
.