AND and OR operators in javascript

Playing around with && and ||

by Yurii Predborskyi

HTML

<div id='wrapper'>
  <div id='container'>
  
  </div>
</div>

CSS

#wrapper {
  font-family: monospace;
  background-color: white;
}

JavaScript

document.getElementById('container').innerHTML += '&& - AND, greedy. Processes all elements in sequence (every pair of && comparisons). In case of failure (one side is false) it returns first element that failed. If nothing fails, it returns the last element checked.' + '<br>';
document.getElementById('container').innerHTML += ('0 && 1 && 2 = ' + (0 && 1 && 2) + '<br>');
document.getElementById('container').innerHTML += ('1 && 2 && 0 = ' + (1 && 2 && 0) + '<br>');
document.getElementById('container').innerHTML += ('1 && 2 && 3 = ' + (1 && 2 && 3) + '<br>');
document.getElementById('container').innerHTML += '<br>';
document.getElementById('container').innerHTML += '|| - OR, lazy. Returns the first element that produces a "truthy" result and stops executing.' + '<br>';
document.getElementById('container').innerHTML += ('0 || 1 || 2 = ' + (0 || 1 || 2) + '<br>');
document.getElementById('container').innerHTML += ('2 || 3 || 4 = ' + (2 || 3 || 4) + '<br>');
document.getElementById('container').innerHTML += ('5 || IIFE (()=>{ alert("hello"); return true; })() || 4 = ' + (5 || (()=>{ alert('hello'); return 'alert(hello)'; })() || 4) + ' - to test replace 5 with 0<br>');