Basic knowledge about JavaScript data type_js tutorial

Source: Internet
Author: User
This article begins with the introduction of javascript data types, and then describes the six types of javascript data: Number, Boolean, String, Null, Undefined, and Object, the following is an example of the typeof operator. 1. What is the data type?

For the vast majority of programming languages we are dealing with, data is classified, including numbers, characters, true and false logic: int, long, string, boolean .... we all know that computers use binary data processing. Load data into the memory and compute the final result through CPU scheduling. Is the data type recorded during memory storage? I think the answer is no. The data in the memory should be distinguished and calculated based on the memory occupied. The two types of data are calculated, for the CPU, only two data with different memory sizes are scheduled for computing. Therefore, for the CPU, the data is only 1 and 0. There is a problem here. Some people may say that a certain two types of data in Java cannot be directly computed and must be converted before calculation. Here, there is a difference between strong and weak types. Strong languages will strictly check each type of data, that is, they will check the space occupied by each type of memory. If they do not meet the requirements, compilation or running is not allowed. The weak type does not strictly check the data, and most data types can be computed directly. JavaScript is a weak type.

2. What types of JavaScript are available?

Includes the following types:

Number: that is, numbers include floating-point numbers.
Boolean: true or false)
String: String
Null: Null Object Pointer, indicating that the directed memory space does not exist
Undefined: Undefined. It indicates that the specified memory space exists, but no data exists.
Object: a complex data type. If you are familiar with a Java object-oriented language, you should understand this well.

Data can be classified through the above 6 types. For the data container JavaScript, the keyword var is used for declaration. How can we determine the type of a variable? This requires the keyword typeof.

Here, we need to note that typeof is an operator (similar to +,-, *,/), rather than a function, you can directly use typeof a (although this is not recommended ). While null and undefined are equal in an hour. Because undefined is derived from null.

Below is an example of typeof

The Code is as follows:


Var mesage = 'some string ';
Var obj = new Object ();
Var;
Alert (typeof message); // 'string'
Alert (typeof (message); // 'string'
Alert (typeof (95); // 'number'
Alert (typeof (a); // 'undefined'
Alert (typeof (null = undefined); // 'boolean'
Alert (null = undefined); // 'true'
Alert (obj); // 'object'
Alert (null); // 'object' (it may also be 'null' in different browsers ')

The above is all about the javascript data type. I hope you will like it.

Related Article

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.