Operators

Logical or (||)

Try the free JavaScript compiler

Returns the left operand when it is truthy; otherwise evaluates and returns the right. Legitimate zero or empty string may be replaced by a fallback.

Formal Syntax & Structure

javascript syntaxjavascript
left || right

Parameters & Attributes

NameTypeDescription
leftexpressionLeft operand.
rightexpressionRight operand; short-circuiting may skip evaluation where applicable.

Return Value

operand value

Result of the operation.

Working Example

Example Snippetjavascript
console.log("" || "default");
JavaScript Reference