I am using the following code to count elements in a string and store them in an Object.
let count1 = {},
count2 = {},
for (n of str1) {
count1[n] = (count1[n] || 0) + 1;
}
for (n of str2) {
count2[n] = (count2[n] || 0) + 1;
}
the result seems to be an object that sort itself without an explicit sort function (ie key-value pairs are accumulated in a sorted order and not the order in which they were added.)
is this always the case in JS?