title: String to Boolean using ternary operator in Javascript?
body: <p>I have a result coming from PHP side and <code>json_encode</code> send all the values as string (not as it's original type). The string coming at <code>quote_tax</code> is a <code>1|0</code> and of course this is <code>true|false</code> for example:</p>
  
  <pre><code>{
    "country_id": "3",
    "country_name": "Italy",
    "contract_tax": "1",
    "quote_tax": "0",
    "contract_inflation": "0",
    "quote_inflation": "0"
  }
  </code></pre>
  
  <p>When I want to perform some operation based on such values and because they are coming as string I need to do something like this:</p>
  
  <pre><code> data.quote_tax == '1' 
                  ? $('#contract_tax').val(1).attr('checked', 'checked') 
                  : $('#contract_tax').val(0).removeAttr('checked');
  </code></pre>
  
  <p>I did know about <code>.parseInt()</code> to convert them into a integer but I believe then I would need to have the same comparison but this case comparing with <code>INT</code>:</p>
  
  <pre><code> data.quote_tax == 1 
                  ? $('#contract_tax').val(1).attr('checked', 'checked') 
                  : $('#contract_tax').val(0).removeAttr('checked');
  </code></pre>
  
  <p>I have tried this way:</p>
  
  <pre><code> Boolean(data.quote_tax) == true 
                  ? $('#contract_tax').val(1).attr('checked', 'checked') 
                  : $('#contract_tax').val(0).removeAttr('checked');
  </code></pre>
  
  <p>And it doesn't work since <code>Boolean(data.quote_tax)</code> always evaluate as <code>true</code> even if <code>data.quote_tax = '0'</code>. </p>
  
  <p>I have check this posts already but I couldn't found a proper solution:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/263965/how-can-i-convert-a-string-to-boolean-in-javascript">How can I convert a string to boolean in JavaScript?</a></li>
  <li><a href="https://stackoverflow.com/questions/4344542/convert-string-to-boolean-in-javascript">Convert string to Boolean in javascript</a></li>
  </ul>
  
  <p>Any ideas what's wrong here or how to do this? </p>