课程: JavaScript: Best Practices for Data
今天就学习课程吧!
今天就开通帐号,24,700 门业界名师课程任您挑!
Add parentheses to clarify logic - JavaScript教程
课程: JavaScript: Best Practices for Data
Add parentheses to clarify logic
- [Instructor] The start code for this video generates three choices randomly from an array, then it has the logic to ensure all three are different. Line 21 is pretty straightforward, but in line 24, I'm checking to make sure the third choice variable is different from first choice and from second choice. If my screen was a little smaller, that statement would even run over a couple lines, and it uses a total of three operators. That can make it hard to read, and every time I come to this line while debugging, I have to stop for a minute to remember just what it's doing. Both mathematical and logical operations in JavaScript have a specific order that the parser follows. For instance, this is the order of operations for a few common logical operators. As long as I'm writing code with this order in mind, it'll work correctly. But there's a difference between a parser understanding the code and me or another developer…
随堂练习,边学边练
下载课堂讲义。学练结合,紧跟进度,轻松巩固知识。
内容
-
-
-
-
-
-
-
(已锁定)
Use triple-character equality operators2 分钟 56 秒
-
(已锁定)
Don't use Yoda conditions1 分钟 52 秒
-
(已锁定)
Compare appropriately for the data type2 分钟 2 秒
-
(已锁定)
Use ternary statements judiciously3 分钟 23 秒
-
(已锁定)
Add parentheses to clarify logic2 分钟 3 秒
-
(已锁定)
Challenge: Compare values53 秒
-
(已锁定)
Solution: Compare values9 分钟 29 秒
-
(已锁定)
-