I want to know the logic of the following operators
let test = ! + [];
console.log(test); //true
Why?
I can't test ! in any way
typeof ! //ERROR
! && true //ERROR
I want to know the logic of the following operators
let test = ! + [];
console.log(test); //true
Why?
I can't test ! in any way
typeof ! //ERROR
! && true //ERROR
! is an operator like +.
If you're going to do typeof + you'll get the same error.
Operators can't be used like that.
The reason why let test = ! + []; worked is because of the order of operation (operator precedence), and it determined the following order:
[];+[] //0;!0 //true.So, in expr !+[], +[] was executed first, that is why Quentin pointed to that dupe
Read more about expressions and operators on JS MDN