一些小小的 javascript 數學運算,第一個是快速的無條件設去的方式,但是用 "~~" 開頭會在 jslint 被擋下,雖然是較為快速,但使用時還是必須考量一下整體的 coding style,下面的是把變數強轉為 boolean,這也是個更快速的方式,但一樣會被 jslint 擋下,斟酌使用。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var a = (99.3 / 18.6) | 0; // 5 | |
var b = ~~(99.3 / 18.6); // 5 | |
window === true // false | |
!!window === true // true |
沒有留言:
張貼留言