4 ms·
> Why/how would you get to the point where you're operating on the value without being certain of its type? My favorite example of this is the twitter API, whi
by sheetjs 12y ago
> Why/how would you get to the point where you're operating on the value without being certain of its type?
My favorite example of this is the twitter API, which used to report retweet count as the string "100+" for the case of over 100 retweets. This behavior was not documented [1], so until you encounter that example, you wouldn't necessarily expect this or defend against a string
[1] From 2012 http://gazit.me/2012/01/09/Twitter-documentation-fail.html http://gazit.me/2012/01/09/Twitter-documentation-fail.html
- jessedhillon 12y agoHow could === defend you in this case? `"100+" != 100` already. If you do a typeof before further processing the value then you'll know how to treat it, and additionally someone who comes after you will realize that the value could be a number or a string.
- _ZeD_ 12y agoyes, but ``"100+" > 100`` is ``false``
- jessedhillon 12y agoSo... you'd have to parseInt anyway?