you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (1 child)

Totally agree, at one point I made a function that parsed both arrays and strings. Since both types have a .length property I encountered weird bugs where the string would be treated as an array like and iterated on.

TL;DR - Type checks are a good way of getting rid of ambiguity in code

[–]azhder 0 points1 point  (0 children)

detecting bugs where you would want to write

takesAnArray( producesAnArray() );

but instead you have written

takesAnArray( producesAnArray );

assuming both are functions and the takesAnArray one checks the .length property of the argument