Scope
Q: What will be printed on the console?
(function () {
var a = (b = 5);
})();
console.log(b); // $: 5
- variable
ais declared using the keywordvaras local function variable - b is not defined using
varand is assigned to the global scope - doesn't use strict mode (
'use strict';) inside the function- strict mode requires you to explicitly reference to the global scope
var a = window.b = 5;
- strict mode requires you to explicitly reference to the global scope
(function () {
'use strict';
var a = (b = 5);
})();
console.log(b); // $: Uncaught ReferenceError: b is not defined