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

前端 未结 6 1628
死守一世寂寞
死守一世寂寞 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:36

    Single "=" means "assign to the left var".

    As a return value for the IF, you get the value assigned, and since it is 1, the "true" branch is executed.

    However, if you put "var" into the IF, it won't return the assigned value, and I think it won't even work at all.

    Mistaking "=" and "==" is a common typo.

提交回复
热议问题