JavaScript If statement condition with no operator? What does it do?

前端 未结 4 1491
天命终不由人
天命终不由人 2021-01-01 17:10

I am used to if statements having a condition where ( x < y ) or ( x == y ). But in cases where there is no operator, what does the if statement check exactly? i.e. in th

4条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-01 17:35

    As long as the expression inside the parentheses returns something other than false, null, 0, "" or undefined... the block in the if statement will be executed :-)

    In fact all of the following will work:

    
    

提交回复
热议问题