Read Catalogue
- Number
- String
- Boolean
- Null
- Undefined
- Object
Today began to seriously study JS, although in the common development of Java EE often use JS but not proficient, this essay note JS and Java data type differences
Back to top number
Unlike Java, JS is a weakly typed language, even if there is no clear distinction between floating-point numbers and integers, the number value can be var a = 5 or 5.5, and other binaries such as octal var a = 070. Even science counts var a = 3.12E3.
var a=1; var a=1.2; var a=0xa; var a=3.14e7;
and some special values
NaN (not a number);
Infinity: Values that cannot be computed such as
var a = 1/0;
Go back to the top of string
Compared to Java does not strictly distinguish between single or double quotation marks
var a = ' hello '; var a = "Hello";
Go back to the top of the Boolean
No difference from Java
Go back to the top of NULL
It is similar to the concept of NULL in Java, but exists as a type in the JS weakly typed language.
Back to top of undefined
For definitions that are not auxiliary, or simply undefined variables exist as undefined, the value is lowercase undefined.
(The above is the underlying type of data)
Back to top of object
The object representation of JS is actually more like a special map in Java where value can function, which holds a set of unordered pairs of name values, object is a reference type.
var ob={ name: ' Zhang San ', age:32, sleep:function() {console.log (' zzzzz~ ');}}
As the characteristic of weak language, JS variable type can be converted at any time, if you need to trace the variable type in JS running process, you can use type of.
The difference between JS and Java data types