Java Reference
In-Depth Information
Table 4-6. The List of Value Types and Their Corresponding Converted Boolean Values
Value Type
Converted Boolean Value
Undefined
false
Null
false
Boolean
Identity conversion
Number
Evaluates to false if the argument is +0 , -0 , or NaN ; otherwise,
evaluates to true
String
The empty string evaluates to false . All other strings evaluate
to true
Object
true
You can also use the Boolean() global function to explicitly convert a value to the
Boolean type. The function takes the value to be converted as an argument. The following
snippet of code contains some examples of implicit and explicit conversions to the
Boolean type:
var result;
result = undefined ? "undefined is truthy" : "undefined is falsy";
print(result);
result = null ? "null is truthy" : "null is falsy";
print(result);
result = 100 ? "100 is truthy" : "100 is falsy";
print(result);
result = 0 ? "0 is truthy" : "0 is falsy";
print(result);
result = Boolean("") ? "The empty string is truthy"
: "The empty string is falsy";
print(result);
result = 'Hello' ? "'Hello' is truthy" : "'Hello' is falsy";
print(result);
 
Search WWH ::




Custom Search