Previous wordsFor type conversions, the two common methods for objects are ToString () and valueof (). In fact, these two methods can also be applied to the wrapper type. The ToString () method, described earlier in this article, describes the
Deep understanding of ToString () and valueof () functions
1. Why do we have to understand both of these methods
It is well known that the toString () function and the valueof function, which are objects of the object class, are inherently owned,
Original link: http://www.cnblogs.com/imwtr/p/4392041.htmlConversion of dataAll objects inherit two conversion methods:The first is ToString (), whose function is to return a string that reflects the objectThe second is valueof (), whose function is
1. Why do we need to know both of these methodsAs we all know, the toString () function and the valueof function, these two functions are inherently owned by objects of the object class, and they can also allow us to rewrite, so what is the use of
Basically, all JS data types have these two methods (except NULL), they solve the JS value operation and display problems, the following to see the difference between the two methods.The valueof () method returns the original value of the Array
Conversion of dataAll objects inherit two conversion methods:The first is ToString (), whose function is to return a string that reflects the objectThe second is valueof (), whose function is to return its corresponding original valueToString
The relationship between ToString and valueof in type conversion and its difference analysis
The first is to see how ES5 's specifications are explained.Here are a few basic knowledge points to look at:
[[class]] [[class]] is an
Package method.usually;Import java.text.ParseException;Import Java.text.SimpleDateFormat;Import Java.util.Calendar;Import Java.util.Date;Import Org.json.JSONObject;public class Typemethod {public static void Main (string[] args) {Comparison of two
valueof (): Returns the original value that best fits the object type;ToString (): Returns the original value of the object as a string.
These two methods are generally referred to JS to implicitly call to meet the different operations.In numerical
Basically, all JS data types have both valueof and ToString methods, except NULL. Both of them solve the problem of JavaScript value operation and display.
1. The usage is as follows:
ToString () Method: Returns a string representation of an
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.