There exist the function Number.toLocaleString, where the first argument (locale) can be omitted to provide the current host locale.
Described as (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString):
// Use the host default language with options for number formatting
var num = 30000.65;
console.log(num.toLocaleString(undefined, {minimumFractionDigits: 2, maximumFractionDigits: 2}));
// → "30,000.65" where English is the default language, or
// → "30.000,65" where German is the default language, or
// → "30 000,65" where French is the default language
Now I changed in my browser the languages and selected "dutch" to the top (under chrome://settings/languages). This made navigator.languages return ["nl", "en-NL", "en-GB", "nl-NL", "en-US", "en"]
However when I then use:
var num = 30000.65;
console.log(num.toLocaleString(undefined, {minimumFractionDigits: 2, maximumFractionDigits: 2}));
The result is 30,000.65 - using still the english locale. If I use navigator.languages instead of undefined the result is as expected. (30.000,65).
Where does javascript get the locale from? How can I change the current of my browser? Even my OS (ubuntu) is set to dutch locale.