You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
386 B
JavaScript
25 lines
386 B
JavaScript
9 years ago
|
http://www.sitepoint.com/javascript-truthy-falsy/
|
||
|
|
||
|
function assert(condition, message) {
|
||
|
if (!condition) {
|
||
|
throw message || "Assertion failed";
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// XXX == false
|
||
|
//
|
||
|
// falsy
|
||
|
assert(!(false));
|
||
|
assert(!(0));
|
||
|
assert(!(""));
|
||
|
assert(!(null));
|
||
|
assert(!(undefined));
|
||
|
assert(!(NaN));
|
||
|
|
||
|
// truthy
|
||
|
assert(!!("0"));
|
||
|
assert(!!("false"));
|
||
|
// empty functions
|
||
|
// empty array
|
||
|
// empty object
|