课程: JavaScript: Best Practices for Data
今天就学习课程吧!
今天就开通帐号,24,700 门业界名师课程任您挑!
Use ternary statements judiciously - JavaScript教程
课程: JavaScript: Best Practices for Data
Use ternary statements judiciously
- My code for this video using a couple ternary statements to choose between values based on the truth value of a condition. On line seven, I'm setting a Boolean value for a variable based on the value of a property of my object. On line nine, I'm choosing the text to be logged based on whether I have custom text to display. Turnery statements are meant to serve as a quick substitute for larger logic patterns when you only need to make a quick comparison. They're more compact, which means you have the classic trade off of fewer characters at the cost of denser code that can be harder for a human to parse. Because of the potential draw backs of ternary statements, it's important to use them only when necessary. ESLint has a rule that flags ternaries that could easily be replaced. It also has a rule that lets you flag nested ternaries for elimination. Nested ternaries make that short, hard-to-parse code even more complex and to…
随堂练习,边学边练
下载课堂讲义。学练结合,紧跟进度,轻松巩固知识。
内容
-
-
-
-
-
-
-
(已锁定)
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 秒
-
(已锁定)
-