Differences between toString of and toLocaleString of in JavaScript
- 2021-07-21 07:01:15
- OfStack
These two methods are used occasionally
Then, when converting numbers into strings, I don't feel any difference between these two methods, as follows:
var e=123
e.toString()
"123"
e.toLocaleString()
"123"
Right, it doesn't make any difference
Let's continue to look at the difference between these two methods when converting arrays into strings. Look, the code is as follows
var aa=[1,2,3]
aa.toLocaleString()
"1,2,3"
aa.toString()
"1,2,3"
It doesn't make any difference
Then look on the Internet and find that there seems to be a difference in the conversion time format, so look at it, the code is as follows:
var sd=new Date()
sd
Wed Feb 15 2017 11:21:31 GMT+0800 (CST)
sd.toLocaleString()
"2017/2/15 Morning 11:21:31"
sd.toString()
"Wed Feb 15 2017 11:21:31 GMT+0800 (CST)"
Well, I can see the difference clearly in this way