I am getting confusing results on the undefinded check.
In my memory and according to multiple answers (1 2 3 4 5), the following code should work.
// bar is not defined
if (bar) console.log("should not execute");
if (!bar) console.log("should execute");
var foo = bar || 'foo'; // should assign 'foo' but is undefined
But on Chrome (Version 63.0.3239) and Firefox Nightly (Version 60.0a1) I get a
Uncaught ReferenceError: bar is not defined
This happens on console and linked scripts without strict mode
// linked-script.js
(function() {
if (bar) console.log("should not execute");
if (!bar) console.log("should execute");
var foo = bar || 'foo';
})();
// index.html
<script type="text/javascript" src="linked-script.js"></script>
What am I missing?