Single line if else condition


/ Published in: JavaScript
Save to your folder(s)



Copy this code and paste it in your HTML
  1. var x = "True";
  2. var b = getBoolean(x);
  3. alert(b);
  4.  
  5. function getBoolean(s)
  6. {
  7. return s.toLowerCase()=='true'?true:false;
  8. }
  9.  
  10. // Another simple example
  11. var a = 11;
  12. a == 10 ? alert("true") : alert("false");

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.