4 ms·
since $("foo") returns a jQuery object that has a method html then it is valid , like [].forEach(myFunc) is valid: a empty array is not an error. there may be
by camus 14y ago
since $("foo") returns a jQuery object that has a method html then it is valid , like [].forEach(myFunc) is valid: a empty array is not an error. there may be other relevant cases but i dont think this one is.
- joshuahedlund 14y agoThat's precisely my point. To put it another way, jQuery converts what would be a javascript error into a technically "valid" empty array. Sometimes this is useful, but it can also help mask poor logic.
- camus 14y agoI doing agree, it is not a javascript error ! again if i take the array exemple and the following code : var a = [1,2,3,4] // now i filter the array var b = a.filter(function(a){return a<0} ); // b = [] // now do something on b b.forEach(function(e){console.log(e)}) // will "fail" silently , because it will output nothing is what i'm doing stupid ? yes, but it is 100% valid from a javascript perspective. It is a coding error , but not a JS error.