12
crisz
6y

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

Comments
  • 0
    @norman70688 yes. Particularly when you expect that something is well designed and actually it's not
  • 0
    @norman70688 I agree, but in some languages (like Java) null is a valid member of the string type
Add Comment