Tally the occurrences of some numbers
This is perfectly fine JavaScript, performant even. However...

var i, a, tally = {}, arr = [1, 3, 7, 9, 3, 1, 6, 3, 3, 2, 11, 2];


For better visibility, it's recommended you split up each variable to its own var. Also, to avoid gotchas and IDEs screaming "potentially uninitialized variable" (Intellij does this), initialize them with values.

for (i = 0; i &lt; arr.length; i++) {
  a = arr[i];
  tally[a] = (tally[a] || 0) + 1;
}


Perfectly fine, except it can be better if you use let on i. That way, it strongly indicates that i lives only within the loop body and not anywhere else.

An alternate way to do this is to use array.reduce and carry around the tally object until done. This way, you avoid having to define temporary storage variables and counters.

const arr = [1, 3, 7, 9, 3, 1, 6, 3, 3, 2, 11, 2];
const tally = arr.reduce(function(tally, value){
  tally[value] = tally[value] ? tally[value] + 1 : 1;
  return tally;
}, {});


or more concisely, but entirely unreadable depending on who you ask

const arr = [1, 3, 7, 9, 3, 1, 6, 3, 3, 2, 11, 2];
const tally = arr.reduce((t, v) =&gt; (t[v] = (t[v] || 0) + 1, t), {});