JS-Implicit conversion

Source: Internet
Author: User

first, the JS data type is divided into 6 kinds, namely null, Undefined, Boolean, string, number, object. Where object is a reference type, the remaining 5 types are basic or are called primitive types.

Type conversion is an implicit conversion! The types are converted before different types of variables are compared. Implicit conversions typically occur when operators add, subtract, multiply, divide, and are greater than, less than, and so on.

The typeof () method is used to print to determine what data type an element is.

1. Conversion of strings and numbers to each other:

(1), string plus number | | Numbers plus strings, numbers = = strings


typeof ("Hello"); = = "string"

typeof (2); = "Number"

typeof ("6"); = = "string"

"Hello" + 2 = "Hello2"

2 + "Hello" = "2hello"

"6" + 2 = "62"

2 + "6" = "26"

(2), number minus string | | string minus number, String = = Number (at this point, the string is a pure number)

Number Minus string | | string minus number, String = = NaN (at this point, the string is not a pure number)

String minus string, String = = Number (at this point, the string is a pure number)

String minus string, String = = Nan (not a purely numeric string converted to Nan)


2-"hello" + = NaN

2-nan = NaN

     "Ten"-5 = 5

"Hello"-5 = NaN

"+"-"+" = -

"Hello"-"ten" = NaN

"Hello"-"hello" = = NaN

JS-Implicit 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.