title: Return statement inside JavaScript ternary operator expression
body: <p><strong>QUESTION</strong></p>
  
  <p>Is there a way to execute a <code>return</code> statement inside of a <strong>ternary operator</strong>?</p>
  
  <p>It's a weird thing, because I feel like a <strong>ternary</strong> is like a shorthand for an <strong>if/else</strong>, and you CAN execute a <code>return</code> statement inside an <strong>if/else</strong>.</p>
  
  <p>But for some reason, I'm not able to execute a <code>return</code> statement inside of a <strong>ternary operator</strong>:</p>
  
  <p><strong>Regular IF/ELSE:</strong></p>
  
  <pre><code>// THIS WORKS
  function foo() {
    if (true) {
      console.log('This is true');
    } else {
      console.log('Not true');
    }
  }
  </code></pre>
  
  <p><strong>TERNARY as IF/ELSE:</strong></p>
  
  <pre><code>// THIS ALSO WORKS
  function bar() {
    true ? 
      console.log('This is true')
    : console.log('Not true');
  }
  </code></pre>
  
  <p>Both codes above works just fine. But when return is involved, the following happens:</p>
  
  <p><strong>Regular IF/ELSE with return:</strong></p>
  
  <pre><code>// THIS WORKS
  function foo() {
    if (true) {
      console.log('This is true');
    } else {
      return;
    }
  }
  </code></pre>
  
  <p><strong>TERNARY as IF/ELSE with return:</strong></p>
  
  <pre><code>// THIS DOESN'T WORK
  function bar() {
    true ? 
      console.log('This is true')
    : return;
  }
  </code></pre>
  
  <hr>
  
  <p><strong>CONCERNING POSSIBLE DUPLICATES:</strong></p>
  
  <p>I have looked around and didn't find an answer to this exact question.</p>
  
  <p>It's clear to me that <strong>I can return a ternary operator</strong>, like the following piece of code, but this is not what this question is about.</p>
  
  <pre><code>function foo() {
    return(
      true ?
        console.log('This is true')
      : null
    );
  }
  </code></pre>