title: How does the single equal sign work in the if statement in javascript
body: <p>Recently I saw a statement that works in javascript on the internet and I wonder what the meaning of a single equal sign (=) in javascript as I mostly use in if statements is.<br>
  It is a comparison function which include double equal sign (==)</p>
  
  <pre><code>if(i = 1) {
      alert(i);
  }
  </code></pre>
  
  <p>This works, I wondered what would happen when the if statement gets assigned to the value of 1 to the variable i and check the value of i which is the same as:</p>
  
  <pre><code>i = 1
  if(i) {
      alert(i)
  }
  </code></pre>
  
  <p>But I soon realised that the assignation of a value variable needs to have the keyword var
  so I changed the code to:</p>
  
  <pre><code>  if(var i = 1) {
          alert(i);
    }
  </code></pre>
  
  <p>This time the code doesn't work. Why?</p>