I am really confused by this. If I do something like this:[1].slice(1)it returns an empty array (in the chrome interactive console). But if I compare:[1].slice(1) === []he is always false. So my question is: what really returns [1] .slice (1)?
[1].slice(1)
[1].slice(1) === []
=== compares objects by links.You are comparing two different array objects that are empty.
===
If you want to check if the array is empty, check if .length === 0 .
.length === 0
This is not a slice or === problem.
slice
If you execute [1]==[1] , it returns false .
[1]==[1]
false
This is because both == and === compare objects by reference
==
[] === [] also returns false. [1].slice(1) really returns []
[] === []
[]
Better check the length:
[1].slice(1).length; // falsey