The difference between ToString and tolocalestring in JavaScript

Source: Internet
Author: User
Tags object object

ToString: No parameter, returns a string representing the value of the object that called the method. JavaScript calls this method when the object needs to be converted to a string.

The return value of the default ToString () method has a very small amount of information (but is useful in detecting the type of the object);

var s = {x:1,y:1}.tostring (); The code evaluates to the string "[Object Object]"

toLocaleString (): Object has a tolocalestring () method that returns a localized character representing the object;

The default toLocaleString () method in object does not do any localization of its own operations, it only calls the ToString () method and returns the corresponding value. The date and number classes have been customized for the toLocaleString () method, and can be used to localize conversions of numbers, dates, and times. The toLocaleString () method of the array class is much like the ToString method, except that each array element calls the toLocaleString () method to convert to a string instead of calling the respective ToString () method;

Number object:

var e=123e.tostring () "123" e.tolocalestring () "123"
Array object:
var aa=[1,2,3]AA.  toLocaleString() "A-I"aa.  ToString()"The              " 
Date object:
VarSd=New Date()Sdwed feb 15  2017 11: 21:31 Gmt+ 0800  (cstsd. ()  "2017/2/15 a.m. 11:21:31" < Span class= "PLN" >sd. ()  "Wed Feb 11:21:31 gmt+0800 (CST)"    


The difference between ToString and tolocalestring in JavaScript

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.