Here is a simple example: I have two functions: someFunction
and someFunction2
.
someFunction
recognizes someFunction2
event thoug it is defined after someFunction
. It is different with the object someVar
thoug. If it is defined after the function that uses it, it is not recognized by the function hence undefined
. But if the object is defined before the funcution that uses it the function itself recognizes the objec. Here is an example that showcase:
function someFunction() {
console.log(someVar)
someFunction2()
}
someFunction()
function someFunction2() {
console.log("Some Function 2 has been called")
}
var someVar = 'Some Var Displayed Here'
In the case above someFunction
recognizes someFunction2
but doesn't recognize the object someVar
WHY? what is the difference between the someFunction2
and someVar
?