If You Ever Wanted to Know How JavaScript Conditional Operators Executes


A basic conditional operators && OR || execution demo in JavaScript:

  1. Using the || operator (OR)
    if (confirm('Do you agree, or...') || confirm('...do you wish to revert?')) {
    alert('As you wish...');
    }

     
    If you click OK for first confirm() you will not see the second confirm(). When you use the || operator all conditions are checked until one is true.


  2. Using the && operator (AND)
    if (confirm('Do you agree, and...') && confirm('...do you really confirm to agree?'))  {
    alert('As you wish...');
    }




    Even If you click OK for first confirm() you will still see second confirm(). When you use the && operator all conditions are checked and all must be true.