Skip to content

@stoive /undefined.js
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Two types of undefined
new Array(10).length
// evaluates to `10`
new Array(10).map(function(current, i) { return i });
// evaluates to `[]`
var arr = [];
arr[2] = undefined;
arr[9] = undefined;
console.log(arr);
// logs `[undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined]
console.log(arr.map(function(current, i) { return i }));
// logs `[undefined, undefined, 2, undefined, undefined, undefined, undefined, undefined, undefined, 9]`
arr.map(function(current, i) { return i }).forEach(function(current, i) { console.log(i) });
// logs `2`
// logs `9`
for (var i in arr) console.log(i);
// logs `2`
// logs `9`
for (var i = 0; i < arr.length; ++i) console.log(arr[i]);
// logs 10*`undefined`
/*
* Any guesses on how to tell the difference between `undefined` and, err, `undefined`?
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.