Chained Variable Declarations
Video
JavaScript Notes
JavaScript
(function f1() {
var a = 1,
b = 1;
var x = y = 2; // no var is applied to y!,
// so JS assigns the variable to the next upper scope (global scope)
})();
(function f2() {
let j = 1,
k = 1;
let r = s = 2; // no let is applied to s!
// so JS assigns the variable to the next upper scope (global scope)
})();
//what are the values for a, b, x, y, j, k, r, s in the global scope?
//which of these variables will exist on the window/global object?
//var is function scoped, let is block scoped
console.log(global.s);
Feedback
Submit and view feedback