What do you mean by "|" in js?

clipboard.png

as shown above, what do lines 2 and 3 mean

Mar.18,2021

| | indicates logic or, and attempts to convert the left side of the symbol to a Boolean object. If the left side is true , the result of the expression is the left side value, and if it is false , the expression result is the right side value.

in the age of ES5, this writing was mostly used to deal with default values.

combined with screenshot: if nodes [link.source] is < del > empty < / del > false , then nodes [link.source] is assigned a Object and returned.
if nodes [link.source] is not < del > empty < / del > false , then return nodes [link.source]

directly.

P.S. The false mentioned above is not Boolean false, in the real sense, but all the values that can be converted to false , including null , undefined , 0 and so on

. The

logic is somewhat similar to the default parameter, but looser than the default parameter.
the above code means:
when nodes [link.source] has a value, it is assigned to link.source, not to continue execution | | the following code;
when nodes [link.source] has no value, assign {name: link.source} to Nodes[ link.source] first, and then assign nodes [link.source] to link.source. Always make sure that link.source can get the appropriate value.


OR means that if the previous value exists, the previous value is assigned, the latter value is not executed, and if it does not exist, the latter value is taken.
corresponds to & &, and


this is a logical operator that indicates logical or , that is, logical judgments on both sides of the false return true unless all are false . The corresponding truth table is

.
A     ||     B     
0                0         0
1                0         1
0                1         1
1                1         1

where 0 means false , and 1 indicates true .

when it comes to the program you provide, a feature of or logic operations is used here, that is, the following statements are executed if the preceding false , and the following statements are not executed if the preceding true .
where the second sentence is equivalent to

when nodes [link.source] has value and is not 0 , false , ' (empty string) and other logical false values, assign it to link.source , and do not continue to execute the code following | .
when nodes [link.source] has no value or the values are 0 , false , '0' , first assign {name: link.source} to nodes [link.source] , and then assign nodes [link.source] to link.source . Always make sure that link.source can get the appropriate value. The third sentence following
is similar, except that the position of the value is different.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e417e8-44934.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e417e8-44934.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?