The implicit type conversion in JS

Source: Internet
Author: User

1. When math is in operation

var num = + ' 123 ';

var num1 =-' 123 ';

var num2 = ' 123 '/1;

Console.log (typeof Num1)

Console.log (typeof num)

2.new operator


var num = new number (' Hello ');

Console.log (num)

3 string concatenation no matter the value of any other data type is spliced with a string, it will become a string


var ret = ' 123 ' +456;//123456

var Ret2 = ' 123 ' +{}//object? ' 123[object Object] '

var ret3 = ' 123 ' +[3,4,5]//' 1233,4,5 '

The conversion of an array into a string is a special form that translates into ' 3,4,5 '

Console.log (ret)

Console.log (Ret2)

Console.log (RET3)

Array 456 is converted to a string, followed by string concatenation with the preceding string ' 123 '

Console.log (typeof (new number). ToString ())//String data type

4 If Judgment statement

The IF (' Chuanzhi ') {//if judgment statement internally converts the value of the other data type to a Boolean data type and then determines

Console.log (' Chuanzhi ')

}


The implicit type conversion in JS

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.