For the Javascript function String.prototype.split()
, the MDN web docs give the following interface:
.split([separator[, limit]]) str
Curiously, they also make the following claim:
Notice in particular the center bullet: if limit
is 1
, str.split(separator)[0]
is returned. I know Javascript has a messed-up type system, but this does seem to be a “type error.”1 Indeed, you can try the following in the console of any browser:
"Hello World!".split(" ", 1); // ["Hello"]
"Hello World!".split(" ")[0]; // "Hello"
This is clearly just a silly typo, but it’s always neat to spot one out in the wild. I’ve archived a version of the original page that has this text.
Update: I made an issue in the MDN Github repository, but apparently it’s already been fixed. Loading the page now shows that it is indeed correct. Well, one day I’ll find a typo that no one has found before. If I’m lucky, it’ll be in one of Knuth’s books!
No clue why I’m bringing this up, but talking about types, particularly lists and singletons, brings to mind something cute I once saw on Math Overflow. Can you come up with sets and such that and are both true?↩︎
Comments