1.4 Boolean Type
Literal value: True, False
You can call the Boolean () function on a value of any data type, and always return a Boolean value.
Data type |
The value converted to true |
Value converted to False |
Boolean |
True |
False |
String |
Any non-empty string |
"" (empty string) |
Number |
Any non-0 digits (including infinity) |
0 and Nan |
Object |
Any object |
Null |
Undefined |
N/A |
Undefined |
1.5 Number Type
var intnum = 55; Integer
var floatNum1 = 1.; No digits after the decimal point--resolves to 1
var floatNum2 = 10.0; integer--resolves to 10
var floatnum = 3.125e7; equals 31250000
var 0.2 0.1 ; alert (a// 0.30000000000000004
NaN, or non-numeric (not a number) is a special value that represents an operand that would have returned a numeric value.
No value is returned (this will not throw an error).
// false
Alert (IsNaN (NaN)); // true Alert (IsNaN (10)); // False (10 is a numeric value) // False (can be converted to a value of ten) Alert (IsNaN ("Blue")); // true (cannot be converted to numeric value) Alert (IsNaN (true//False (can be converted to a value of 1)
There are 3 functions that can convert non-numeric values to numeric values: Number (), parseint (), and parsefloat ().
Vi. JavaScript data type (ii)