Javascript split behavior if delimiter is not contained in string

What is the correct behavior

"test".split("/") 

Should the result be ["test"] or undefined? I ask because I have different results for two different javascript engines. Most browsers seem to return ["test"], so I wonder if rejection behavior should be considered an error.

+4
source share
1 answer

the ES5 specification for String.prototype.split does not allow any return result other than an array, so undefined is incorrect.

+3
source

Source: https://habr.com/ru/post/1481343/


All Articles