Javascript| conversions are not the same in Java, for example, when integers are converted to strings, you must use the integer.tostring () static method or the String.valueof () static method to convert the string to an integer. You must use Integer.valueof ().
As you can see, type conversions in JavaScript cannot be viewed as "coercion type conversions".
In JavaScript, the double and int types are all viewed as number objects, so either typeof 1 or typeof 1.0 returns number. So we can let the JavaScript explain the engine inside out without having to go to the int or double type.
If you want to convert number to string, you can use the ToString () method of number, (like (1). ToString () parentheses must or 1. ToString () spaces must otherwise compile an error, if the variable is not required, Or you can call the string () function, both of which automatically invoke the Numbertostring () inside the interpreter engine, or call other functions based on the system, basically similar.
If you want to convert a string to number, you can use the number () function, which automatically determines whether the string is an integer or a floating-point number, and then uses the corresponding data type internally, and you can use global functions parseint () and parsefloat (). They make the transition according to your request. Similarly, they use internal functions such as stringtonumber,stringtoint and so on to explain the engine's internal mechanism.
If you convert double to int, you must use the Math.floor () function (truncate rounding) or Math.Round () (rounded)
int is converted to double, without any problem, the int is treated as a double
Note: The number, String function is a special function, in the JS engine, he will automatically judge whether it is a constructor call or a normal call, so you can use the New keyword, can also be called as a function directly.
About JS reference Manual, Microsoft has a CHM is very good, the Guide, API reference all have, is the Windows scripting technology, Chinese version, I downloaded on MSDN. And about JS explain engine, I refer to Netscape's SpiderMonkey, now by the Mozilla organization maintenance
for (i=0;i<this.all.length;i++) {
Vtotal+=number (This.all[i]. Value);
}
The summation of the numbers
Otherwise it's a string connection.
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.