Javascript - Logical Operator

> (World Wide) Web - (W3|WWW) > Javascript (Js|ECMAScript) > ECMAScript - Grammar Standard

1 - About

Logical operator in Javascript

3 - List

  • &&: AND

3.1 - OR, ||

Returns expr1 if it can be converted to true; otherwise, returns expr2. See Javascript - Boolean (Truthy|Falsy)

expr1 || expr2

Example:

console.log('Return expression1')
console.log(true || 'expr2')
console.log(1 || 'expr2')
console.log('s' || 'expr2')
console.log('\n')
console.log('Return expression2')
console.log(false || 'expr2')
console.log(0 || 'expr2')
console.log('' || 'expr2')

Advertising

3.2 - &&

  • true && expression always evaluates to expression
  • false && expression always evaluates to false

Therefore, in a statement such as condition && expression, if the condition is true, the element right after && will appear in the output. If it is false, it will be ignored.

web/javascript/es/logical_operator.txt · Last modified: 2019/02/16 17:40 by gerardnico