Could anyone explain why the two below are not equal? I'm basically trying to figure out what's happening behind the scenes. My understanding was that they'd both refer to the same function but that doesn't seem to be the case.
var foo = function bar() {}
typeof foo //"function"
typeof bar //"function"
foo === bar //false
foo == bar //false
I don't know about you but my browsers return undefined
for typeof bar
typeof bar //"undefined"
demo http://jsfiddle.net/gaby/t8Czr/
The bar
reference to the method is only available inside the method itself..
Bar is not defined. Bar only exists within the scope of foo.
If you were to declare bar first then set foo equal to bar your results will be as expected.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With