Short-circuit evaluation

by trentHarlem

HTML

<h2>Short-circuit evaluation</h2>

<p>
Logical 'or' || returns the first 'truthy' value. <br/>
Reads like, 'If this OR that are true, then the operation returns true.'
</p>


<p>
Logical 'and' && returns the first 'falsy' value. <br/>
Reads like, 'If this AND that are true, then the operation returns trun.'
</p>

JavaScript

//      logical 'or' || returns the first 'truthy' value
console.log(true||1)
console.log(0||1)
//      logical 'and' && returns the first 'falsy' value
console.log(false&&0)
console.log(1&&0)