cocos2d JS function types to each other (string, shape, float, Boolean)

Source: Internet
Author: User

Work busy days, near time to draw some space to share their own learning JS a little note notes to do a bit of record, big God do not spray, thank you!

1. Conversion of strings

1 varFound =false;2Console.log (Found.tostring ());//Output False3 4 varNUM1 = 10;5 varNUM2 = 10.0;6Console.log (Num1.tostring ());//output "Ten"7Console.log (Num2.tostring ());//output "Ten"8 9Console.log (Num2.tostring ());//Output binary form "1010"TenConsole.log (Num2.tostring ());//output octal form "seven" OneConsole.log (Num2.tostring ());//output hexadecimal form "A"

2. Conversion of int of integer type

1 varNUM1 = parseint ("12345red");//back to 123452 varnum2 = parseint ("0xA");//return ten3 varnum3 = parseint ("56.9");//back to4 varNUM4 = parseint ("Red");//returns a value that NaN indicates is not valid for conversion5 varNUM5 = parseint ("10", 2);//returns the binary number 2 (the second argument is the cardinality, which indicates the value of the binary)6 varNUM6 = parseint ("10", 8);//returns octal number 87 varNUM7 = parseint ("10", 10);//returns a decimal number of ten8 varNUM8 = parseint ("AF", 16);//returns the hexadecimal number 175

3. Conversion of floating-point type

1 varnum3 = Parseflost ("12345red");//back to 123452 varnum3 = Parseflost ("0xA");//return NaN3 varnum3 = Parseflost ("11.2");//Back to 11.24 varnum3 = Parseflost ("11.22.33");//back to 11.225 varnum3 = Parseflost ("0102");//back to 1026 varnum3 = Parseflost ("Red");//return NaN

4. Conversion of compulsory type

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

1     varB1 = Boolean ("");//false-an empty string2     varB2 = Boolean ("Hello");//true-Non-empty string3     varB3 = Boolean (50);//true-not 0 digits4     varB4 = Boolean (NULL);//False-null5     varB5 = Boolean (0);//false-06     varB6 = Boolean ({name: ' Tony '});//true-Object

Note: The Boolean function can convert any type to a Boolean type

(2), number (value)----convert the given value to a tree value

1     varNUM1 = Number (false);//02     varnum2 = Number (true);//13     varnum3 = number (undefined);//NaN4     varNUM4 = Number (NULL);//05     varNUM5 = number ("1.2");//1.26     varNUM6 = Number ("12");// A7     varNUM7 = Number ("1.2.3");//NaN8     varNUM8 = number ({name: ' Tony '});//NaN9     varNUM9 = number (50);// -

Note: The number function can convert any type to a numeric type, null means no value, undefined represents an undeclared variable, or a variable that has been declared but not assigned, or an object that does not exist

(3), string (value)----converts the given value to a string

1     var str1 = String (null);    // "NULL" 2     var str2 = String ({name: ' Tony '});    // "[Object Object]"

Note: The string function can convert any type to a string type

cocos2d JS function types to each other (string, shape, float, Boolean)

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.