Double negation casts a string or a number to a boolean:
var bool = !!num;The following values are equivalent to false in conditional statements:
- false
- null
- undefined
- The empty string
""
(\''
) - The number 0
- The number NaN
var x = "somevalue" var isNotEmpty = !!x.length;
Let’s break it to pieces:
x.length // 9
!x.length // false
!!x.length // true
No comments :
Post a Comment