A quiz about RegExp.prototype.exec return values and numeric indexes (or indices or however you people pluralize that word).

01 May 2014

Given the following user agent string ua and function expression r,

var ua = "Mozilla/5.0 (Android; Mobile; rv:31.0) Gecko/31.0 Firefox/31.0"

r = function (e) {
  if (e.indexOf('android') !== - 1) {
    var t = /android (\d)/gi,
    n = parseInt(t.exec(e)[1], 10);
    return !isNaN(n) && n >= 4
  }
  return !1
}

What's the value of parseInt(t.exec(e)[1], 10)?

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Trick question. You get a TypeError because the [1]th index of null doesn't̗̦͇̮͕̾ ̝̠̥̩̞͙̣ͤ̑ͧ̏ͥe̹͉̘̯̎͒̃x̤͑̿i̬ͮ͑̇̎̉s͉̝̩̲̹͒́t̻͍̻̯̗̅ͅ.̩ͧͯ̆̑̇̒

So what do you win for taking this quiz?

If you happen to work for Comedy Central, your prize is now you know why you have a bug!

If you don't, you can follow this link to entertain yourself with similar bloopers in the wild.