课程: JavaScript: Best Practices for Data
今天就学习课程吧!
今天就开通帐号,24,700 门业界名师课程任您挑!
Rely on implicit Boolean values in conditionals - JavaScript教程
课程: JavaScript: Best Practices for Data
Rely on implicit Boolean values in conditionals
- [Instructor] When you're working with a variable whose value is a Boolean in a conditional expression, it can be tempting to explicitly typecast the variable like you might with a value of a different data type to get its Boolean equivalent. My code for this video is the very beginning outline of a user interface. I'm setting a loggedIn variable to store whether the user is logged in, and then checking the value of this to determine my next step, which I'm simply logging into the console to start. Now in my condition I'm typecasting loggedIn to check whether loggedIn is equal to true. But my condition just needs a true or false value, and my loggedIn variable is definitely going to give it one or the other. So this extra step of typecasting isn't necessary. ESLint has a rule to test for this, no-extra-boolean-cast. It's enabled in the ESLint recommended rules, and by default it's flexible, watching only for Boolean…
随堂练习,边学边练
下载课堂讲义。学练结合,紧跟进度,轻松巩固知识。
内容
-
-
-
-
-
-
(已锁定)
Type cast strings with the String wrapper2 分钟 58 秒
-
(已锁定)
Type cast numbers with the Number wrapper1 分钟 40 秒
-
(已锁定)
Type cast Booleans using double negation2 分钟 14 秒
-
(已锁定)
Rely on implicit Boolean values in conditionals1 分钟 45 秒
-
(已锁定)
Challenge: Type cast1 分钟 7 秒
-
(已锁定)
Solution: Type cast2 分钟 39 秒
-
(已锁定)
-
-