The difference between JS and Java data types

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.