filmov
tv
JavaScript tips — The logical or assignment operator ||=

Показать описание
The logical or assignment operator in #JavaScript be convenient shorthand for logical expressions
Unlike other assignment operators, the logical or assignment operator also short circuits. Right right handsome will not be evaluated if the left hand side is already true
Note that I've intentionally simplified the expanded form of the assignment expression. Something like myVar ||= true actually expands to myVar || (myVar || true). This difference usually doesn't matter, but it means that the short circuiting of the logical or assignment can actually skip assigning values
Unlike other assignment operators, the logical or assignment operator also short circuits. Right right handsome will not be evaluated if the left hand side is already true
Note that I've intentionally simplified the expanded form of the assignment expression. Something like myVar ||= true actually expands to myVar || (myVar || true). This difference usually doesn't matter, but it means that the short circuiting of the logical or assignment can actually skip assigning values