naprej
  • css
  • firefox
  • html
  • javascript
  • mootools
  • mysql
  • php
  • web
09/05/2010

Javascript Shorthand If Else

Using Shorthand Conditional Expressions

Longhand:

if (check == 'OK'){var name = 'Mike';} 
else{var name = 'Joe';}

Shorthand:

var name = (check=='OK') ? 'Mike':'Joe';

Related Posts

Format Currency - Euro in Javascript , Include .js files inside a .js file - Javascript, Grab unique value out of an array in javascript, Regular expression, new RegExp - Javascript, Random Password Function - Javascript
javascript
  • Copyright © 2009 naprej.com