What's the difference between ( | ) and ( || )?

前端 未结 7 1227
故里飘歌
故里飘歌 2020-12-01 14:08

What\'s the difference between | and || in Javascript?

Furthermore, what\'s the difference between & and &&<

7条回答
  •  旧巷少年郎
    2020-12-01 15:03

    one more point i want to add is || operator is used to assign default value in case the value you are assigning is undefined. So for Exapmle you are assigning a obj to some object test and if you dont want test to be undefined then you can do the following to ensure that value of test wont be undefined.

    var test = obj || {};

    so in case obj is undefined then test's value will be empty object.

    So it is also being used for assigning default value to your object.

提交回复
热议问题