课程: JavaScript: Best Practices for Data
今天就学习课程吧!
今天就开通帐号,24,700 门业界名师课程任您挑!
Don't assign variables in chains - JavaScript教程
课程: JavaScript: Best Practices for Data
Don't assign variables in chains
- [Instructor] The code for this video does some basic calculations on a set of items in a shopping cart. It starts off declaring variables, and then in line nine, ensures that the subtotal, shipping, and net total variables are all numbers and have a value of zero, by using a chained assignment. This single statement is certainly concise. But like other statements that perform multiple actions, it can be hard to read it and understand exactly what's going on. For this reason, I prefer to always assign my values with individual statements. This makes each line of code more easily digestible when I read it, and does away with corner cases where chained assignment can create uncertainty. ESLint has a rule that can flag this for me, which is no-multi-assign. I'll start by adding that to my ESLint RC file. So it's no dash multi dash assign, the value of error. And then, saving and switching back, and that error is…
随堂练习,边学边练
下载课堂讲义。学练结合,紧跟进度,轻松巩固知识。