title: Assign variable in if condition statement, good practice or not?
body: <p>I moved one years ago from classic OO languages such like Java to JavaScript. The following code is definitely not recommended (or even not correct) in Java:</p>
  <pre><code>if(dayNumber = getClickedDayNumber(dayInfo))
  {
      alert(&quot;day number found : &quot; + dayNumber);
  }
  function getClickedDayNumber(dayInfo)
  {
      dayNumber = dayInfo.indexOf(&quot;fc-day&quot;);
      if(dayNumber != -1) //substring found
      {
          //normally any calendar month consists of &quot;40&quot; days, so this will definitely pick up its day number.
          return parseInt(dayInfo.substring(dayNumber+6, dayNumber+8));
      }
      return false;
  }
  </code></pre>
  <p>Basically I just found out that I can assign a variable to a value in an if condition statement, and immediately check the assigned value as if it is boolean.</p>
  <p>For a safer bet, I usually separate that into two lines of code, assign first then check the variable, but now that I found this, I am just wondering whether is it good practice or not in the eyes of experienced JavaScript developers?</p>