Skip to content
Advertisement

What difference with them? ‘!arr.length’ and ‘arr.length=0’

What difference with them? ‘!arr.length’ and ‘arr.length=0’

i can’t understand well 🙁

let arr = [] ;

!arr.length 

arr.length = 0

Really appreciate it, if you explain it logically. Thanks.. 🙂

Advertisement

Answer

They are completely different.

!arr.length will evaluate to true if the array has no items. It will evaluate to false if the array has items.

arr.length = 0 will clear the array, removing all its items, and evaluate to 0.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement