What are the drawbacks of using destructuring assignment in JavaScript? Anything to keep in mind while using in react or nodejs?
Asked
Active
Viewed 163 times
-3
-
React is a JavaScript framework. Node.js is a JavaScript interpreter. I have no idea what you are talking about. – Derek 朕會功夫 Feb 27 '18 at 19:51
-
@Derek朕會功夫 hes talking about a javascript language feature... which both use – floor Feb 27 '18 at 19:52
-
3@floor Remind me, what does a JavaScript feature have to do with a framework? It's like saying *anything to keep in mind while using additions in calculus?* – Derek 朕會功夫 Feb 27 '18 at 19:53
-
Destructing offers benefits over drawbacks. linting standards want you to use `let/const { someVar } = this;` over `let/const someVar = this.someVar;` because by spelling it once, it reduces the chance of error by typo – Sterling Archer Feb 27 '18 at 19:58
-
1Drawbacks? It requires an ES6 environment, and you can do very confusing stuff with it, so use it with care. – Bergi Feb 27 '18 at 20:00
1 Answers
3
There are not really any drawbacks that don't exist for other convenience features.
The primary thing to keep in mind is not to forget the let, var, const keyword. Otherwise all destructured may become global.
let { a,b,c } = myObj;

Randy Casburn
- 13,840
- 1
- 16
- 31
-
1If you forget `let`/`var`/`const` [you will get a SyntaxError](https://stackoverflow.com/questions/46103157/node-js-v8-destructuring-bug). – str Feb 27 '18 at 19:58
-
-