var a = 1234567;
console.log(a.toLocaleString())
#=> '1234567'
Why there's no difference between toLocaleString() and toString in this test?
var a = 1234567;
console.log(a.toLocaleString())
#=> '1234567'
Why there's no difference between toLocaleString() and toString in this test?
I was just searching for an answer to this myself. The short answer is that Node.js builds don't have the library for internalization needed for Number.toLocaleString
included by default because it substantially increases the binary size.
You can build Node from source with the library included if you really need it. This other answer has more details if you are interested.
toLocaleString is just a culture-aware version of toString. If you see no difference between them, then the object you call them on has the same representation both in your local culture and in the invariant culture. This pair of methods will give different results in countries where comma is used in floating point numbers instead of dot.
1.23.toLocaleString(); // "1,23"
1.23.toString(); // "1.23"