I'm practicing my coding and I'm still kind of new. While looking for solutions to practice problems I see this kind of code used in loops and I'm curious what this line of code does.
counter[string[i]] = (counter[string[i]] || 0) + 1;
here it is in the full code that is used to count most occured character in a string if this helps
var string = "355385",
counter = {};
for (var i = 0, len = string.length; i < len; i += 1) {
counter[string[i]] = (counter[string[i]] || 0) + 1;
}
var biggest = -1, number;
for (var key in counter) {
if (counter[key] > biggest) {
biggest = counter[key];
number = key;
}
}
console.log(number);