JS Data type Conversion

Source: Internet
Author: User

let's start with a brief look at the data types in JS, which have strings, numbers, booleans, arrays, objects, Null, undefiend 6 data types. At the same time, JavaScript has a dynamic type. That is, the same variable can be used for different types:




Next, let's introduce several types of conversion of data types in JavaScript.

1. Conversion functions
JavaScript provides two conversion functions for parseint () and parsefloat (). where parseint () converts the value to an integer, parsefloat () converts the value to a floating-point number, and the arguments for both functions can only be of type string.
parseint () and parsefloat () will parse the string carefully before judging whether the string is a numeric value. The parseint () method first looks at the character at position 0, determines if it is a valid number, and if not, the method returns Nan, and no further action is taken. However, if the character is a valid number, the method will look at the character at position 1 and perform the same test. This process continues until a character is found that is not a valid number, at which point the parseint () converts the string before the character to a number.
                 


The parseint () method also has a base mode that converts binary, octal, hexadecimal, or any other binary string into integers. A base is specified by the second parameter of the parseint () method.
                 

2. Forcing type conversions
In JavaScript, we can also use coercion type conversions to handle different types of variables.

Boolean (value)--converts the given value to a Boolean type

Number (value)--converts the given value to a digit

String (value)--converts the given value to a string



Today we give you a brief introduction of the data type and data type conversion in JavaScript, for reference only to learn, JavaScript has a lot of knowledge we need to learn, we also continue to study hard.





Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

JS Data type Conversion

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.