Skip to content

Instantly share code, notes, and snippets.

@indexzero
Forked from dherman/range-error-ftw.js
Created November 28, 2012 09:41
Show Gist options
  • Save indexzero/4160168 to your computer and use it in GitHub Desktop.
Save indexzero/4160168 to your computer and use it in GitHub Desktop.
fun with JS arrays
var a = [];
a[Math.pow(2, 32) - 2] = "max index"; // highest non-expando indexed property
console.log(a.length === Math.pow(2, 32) - 1); // true
try {
a.push("whoa", "EVEN MOAR WHOA");
} catch (e) {
console.log(e instanceof RangeError); // true
}
console.log(a.length === Math.pow(2, 32) - 1); // true
console.log(a[Math.pow(2, 32) - 1] === "whoa"); // true
console.log(a[Math.pow(2, 32)] === "EVEN MOAR WHOA"); // true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment