Reading through O'Reilly's JS Definitive Guide and came across this block of code:
let freq = {};
for (let item of "alabama") {
if (freq[item]) {
freq[item]++;
} else {
freq[item] = 1;
}
}
Just want to go over some of the the syntax and implications:
- Assigning an empty object to "freq" variable
- Running the for/of loop over the given string
- If statement checks if freq[item] returns true .. I get that part but what will trigger that truthy value?
- And thus what how would a falsy value be triggered to produce a value of 1?
Thank in advance!
Aucun commentaire:
Enregistrer un commentaire