First, JavaScript basic syntax data type

Source: Internet
Author: User

Weak type: When you define a variable in JS, you do not define an explicit data type, you can convert the type of the variable at any time, and you can convert the type of the variable at any time. The type of the variable depends primarily on the type of literal value stored inside it. Weak type is like the concept of a paper cup, creating a weak type of variable like a paper cup, you can put white water inside, you can put Coke, can put red wine. What is put on is what, and the machine will not deceive.

For example: Var num=12, the keyword VAR is used in the definition of this variable, and the value assigned to it is 12. then you may be wondering what data types will be in JS?

built-in data types : The built-in data types commonly used in JS have number string Boolean, and there is a certain mutual conversion relationship between them, as shown in 1-1

1-1 conversions between the built-in data types

So when it comes to conversions between these data types, there may be a question of how to determine what type of variable the current variable is.

In judging the data type, using the TypeOf keyword, using typeof to determine the type of variables, common types in addition to the above mentioned built-in data types, there are other types, such as object, function, function is not exactly said to be a type, It is the keyword used to define the method. For inter-type conversions and type judgments such as code

View Code

The rules for data type conversions are summarized as follows:

(1) String to value: intercepts a number in a string from the left until a non-numeric character is encountered.

(2) value to Boolean: 0 is False, others are true.

(3) Boolean to value: False is 0,true to 1.

(4) String to Boolean: The empty string is false and the other is true.

First, JavaScript basic syntax data type

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.