The code below will get different in Browser and Node.js.
Result of browser is a
.
Result of Node.js is b
.
if (1) {
function foo() { return 'a'; }
} else {
function foo() { return 'b'; }
}
console.log(foo());
Although this code style is anti-pattern, the code still can be run in environment.
How to explain it?
FYI.
Node.js environment Link: https://repl.it/CgWh
Native Browser environment Link: https://repl.it/CgWj
These links maybe not permanent.
Javascript engines are not hoisting javascript function the same way, so you can expect different behavior between browser/node.
One exemple of this: http://statichtml.com/2011/spidermonkey-function-hoisting.html
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