title: Javascript - Code structuring issue. Returning bool from "if" statement and reuse it in "else if"
body: <p>What would be the practical approach to the issue of this type?</p>
  <p>I'm writing a function which aims to move the div left and right on toggle.</p>
  <p>The approach I have decided to take is as below.
  Can someone explain why this is not working as I expect?</p>
  <p>I'm aware that there may be another solution but this resolving this issue will allow me to use this practice for other scenarios.</p>
  <p>If I understand correctly the bool can not be returned using return statement, but can the variable with bool in it?</p>
  <p>For some reason my function is not reaching to &quot;else if&quot; statement which I thought it would after switching the bool inside of &quot;if&quot;...</p>
  <p>The part of this code is basic so I will not include full script.</p>
  <p>Code:</p>
  <pre><code>menuBtn = document.getElementById('mm');
  menuBtn.onclick = function() {onMenuPress()};
  let sidebar = document.getElementById('sidebar');
  
  function onMenuPress() {
      let move = true;
      console.log(move);
  
      if (move == true) {
          sidebar.style.transform = &quot;translate(-300px)&quot;;
          let move = false;
          console.log(&quot;pressed&quot;);
  
          return move;
      } 
      else if (move == false) {
          sidebar.style.transform = &quot;translate(100px)&quot;;
          console.log(&quot;comeback&quot;);
      }
  </code></pre>
  <p>Thanks for all responses in advance.</p>