How does the single equal sign work in the if statement in javascript

前端 未结 6 1634
死守一世寂寞
死守一世寂寞 2020-12-04 00:42

Recently I saw a statement that works in javascript on the internet and I wonder what the meaning of a single equal sign (=) in javascript as I mostly use in if statements i

6条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-04 01:19

    Single = is an assignment operator and will always equate to true in an if statement (assuming it is a non negative value).

    Double = ,as in ==, is a comparison and will equate to true only if the values on either side of the operator are equal.

提交回复
热议问题