(x > y) { let tmp = x; x = y; y = tmp; } console.log(tmp===x); // ReferenceError: tmp is not defined return [x, y]; } let works similarly to var, but the variable it declares is block-scoped, it only exists within the current block. var is function-scoped. 8
= in const declaration const bar = 123; bar = 456; // TypeError: `bar` is read-only const obj = {}; obj.prop = 123; console.log(obj.prop); // 123 const works like let, but the variable you declare must be immediately initialised, with a value that can’t be changed afterwards. 9
'Doe' }; const {first: f, last: l} = obj; // f = 'Jane'; l = 'Doe' // {prop} is short for {prop: prop} const {first, last} = obj; // first = 'Jane'; last = 'Doe'