Would there ever be an instance when the JavaScript array length property returns a negative value? I'm assuming the answer is no, but I was wondering if there would ever be a need to account for negative values when comparing the length of an array in an if statement, for example.
var x = y.length; if (x === 0) { return false; } else if (x > 0) { return true; } else alert("error"); // is this necessary? }
.lengthcould possibly be negative?yis an array? It could be some other kind of object, with or without a.lengthproperty.