Considering
let obj = {name: 1}; console.log(typeof obj.name, obj.name);
Why is the name identifier passed to the string when using var when assigning destruction to an object?
let obj = {name: 1}; var {name} = obj; console.log(name, typeof name);
But not using let or const ?
let obj = {name: 1}; let {name} = obj; console.log(name, typeof name);
We can avoid this unexpected result by specifying a different identifier.
let obj = {name: 1}; var {name:_name} = obj; console.log(_name, typeof _name);
although it is curious that the var value returns different results than let or const for the identifier name in the browser environment?
javascript ecmascript-6
guest271314
source share