[,'a'].every(x => x==='a')
> True
returns True, although the first item is 'undefined' and therefore should be False?
[,'a'].map(x => x)
> [undefined × 1, "a"]
[,'a'].every(x => x==='a')
> True
returns True, although the first item is 'undefined' and therefore should be False?
[,'a'].map(x => x)
> [undefined × 1, "a"]
The builtin array methods ignore non-existing properties on sparse arrays. The first item is not undefined
, there is no property in index 0
at all. You can try
[,'a'].every(x => x==='a')
> true
[undefined,'a'].every(x => x==='a')
> false
Since undefined is a typeof, use == (twice) instead of three times. It returns true because x is empty and therefore the typeof undefined matches undefined (since you use = three times)