This is the most wtf thing that happened me with Javascript, I had a regular expression and it caused bugs only with 4 digits long words, then I just noticed this:

/^.{3}$/.test(null) // false
/^.{4}$/.test(null) // true

What the fuck, I can't believe that who designed the .test method didn't think to avoid null coercion

  • 0
    Is that one of those cases where abusing language, e.g. ignoring parameter type, is causing surprise and/or disappointment?
  • 0
    @norman70688 yes. Particularly when you expect that something is well designed and actually it's not
  • 0
    Well, fork is actually pretty well designed, but crappy for soup eating. Same goes to function that expects string, but null was passed instead. I can't quite understand why did you think it will work properly with wrong parameter type?
  • 0
    @norman70688 I agree, but in some languages (like Java) null is a valid member of the string type
Your Job Suck?
Get a Better Job
Add Comment