this seems to be a common javascript idiom:
function foo (array, index) {
if (typeof array[index] == \'undefined\')
alert (\'out of bounds baby\'
The only correct way is to check the index vs. the length.
An element may be assigned the value undefined
. It is just silly to use it for a sentinel here. (There may be other, valid and possibly overlapping, reasons for checking for undefined, but not "for an out of bound check" -- the code in the other question will present arguably wrong results when the value of the given arg is really undefined
.)
Happy coding.