Conversion of JS Data Types

Source: Internet
Author: User

Conversion of JS Data Types
First, let's take a brief look at the data types in JavaScript. JavaScript has the data types in string, number, Boolean, array, object, Null, and Undefiend 6. At the same time, JavaScript has dynamic types. That is to say, the same variables can be of different types:

Next we will introduce several types of conversion for Data Types in JavaScript;

1. conversion functions
JavaScript provides two conversion functions: parseInt () and parseFloat. Here, parseInt () converts the value to an integer, and parseFloat () converts the value to a floating point. The parameters of these two functions can only be of the String type.
Before determining whether a string is a numeric value, parseInt () and parseFloat () will carefully analyze the string. The parseInt () method first checks the character at the position 0 to determine whether it is a valid number. If not, the method returns NaN and does not continue to perform other operations. However, if the character is a valid number, this method will view the characters at position 1 and perform the same test. This process continues until a non-valid number is found. At this time, parseInt () converts the string before this character into a number.

The parseInt () method also has the base mode, which can convert binary, octal, hexadecimal, or any other hexadecimal string to an integer. The base is specified by the second parameter of the parseInt () method.

2. Forced type conversion
In JavaScript, we can also use forced type conversion to process different types of variables.

Boolean (value) -- converts a given value to a Boolean value.

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

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


Today, I will give you a brief introduction to the conversion of data types and Data Types in JavaScript For your reference only. There is still a lot of knowledge in JavaScript that we need to learn, and we will continue to study hard.





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: 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.