课程: JavaScript: Best Practices for Data
今天就学习课程吧!
今天就开通帐号,24,700 门业界名师课程任您挑!
Use triple-character equality operators - JavaScript教程
课程: JavaScript: Best Practices for Data
Use triple-character equality operators
- I have an array of some falsy values in JavaScript and I've written code to log the results of comparing each one to the string zero and to the value undefined. My code uses the double equal sign to check for equality which is one of two ways to check for equality in JavaScript Running my code, I get statements logged for the comparisons that are equivalent. And it turns out that the parser sees the string zero as equivalent to both the value zero, and false. And it sees the values null and undefined as equivalent. What? JavaScript has two different ways to compare equality, the algorithms in the parser for the double equal equality sign result in some unexpected equivalences. For instance, false is equivalent to zero, zero as a string, an empty string, and an empty array, but not an empty object, as well as an array containing only the value zero. Now typecasting my values can be helpful here. And double equal results…
随堂练习,边学边练
下载课堂讲义。学练结合,紧跟进度,轻松巩固知识。
内容
-
-
-
-
-
-
-
(已锁定)
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 秒
-
(已锁定)
-