SoFunction
Updated on 2025-04-07

JavaScript logical operator usage skills

JavaScript logical operator usage skills

Here is the case where true is returned

!null //true
!undefined  //true
!0  //true
!NaN  //true
!""  //true

The following is the case where false is returned

!Array  //false
!Function  //false
!String  //false
!Object  //false
!Number  //false
!" "  //false
!100  //false
!"100"  //false

Another usage is to prepend anonymous function! Constitute a self-running function

!function(){
  alert("I have my own independent scope");
}()

Thank you for reading, I hope it can help you. Thank you for your support for this site!