If I have this piece of code (which uses destructuring) seems it's creating new variables ss
and pp
.
But what is the scope of these? Are they created as var
or as let
variables?
Are they function or block scoped?
let config = {
server: 'localhost',
port: '8080',
timeout: 900,
};
/* no let or var here */ ({server : ss, port : pp} = config);
console.log(ss, pp);
My question is not duplicate of the one suggested. I know about var
and what happens if you omit it. The real answer I was looking for here is the one Barmar provided. I just wasn't sure if destructuring assignment behaves exactly the same as normal assignment, or under the hood it assumes var (function) or let (block) scope. That's all. Destructuring was introduced in JS many years after the other question was asked. So it was logical to assume destructuring assignment may have somewhat different semantics than usual assignment. As Barmar confirmed, this is not the case, so I am all set.