4 ms·
lol the null / undefined issue in javascript is further exacerbated by the fact there is no int type and everything is just a "number".... yet the number 0 is s
by ffn 11y ago
lol the null / undefined issue in javascript is further exacerbated by the fact there is no int type and everything is just a "number".... yet the number 0 is still treated the same as null/undefined by js special forms like "if" and "==". This is particularly hilarious because it leads to some null-check bugs like:
if ( user.getScrollPosition() ) { whatever(); } else { die(); }
99% of the time, the code would be fine, but if the user scrolls just right, the whole thing would die. Stuff like this is literally death to debug because this bug is effectively indeterministic and can't be reproduced.
- bcheung 11y agoWhy would you check the value instead of the presence of the value? Rookie mistake. user.getScrollPostion() != undefined or in CoffeeScript just use: user.getScrollPosition()? Arrays have various types of ints and floats of various word lengths and signs. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Typed_arrays https://developer.mozilla.org/en-US/docs/Web/JavaScript/Type...