Ternary operations in JavaScript are really awesome.
It's essentially an if/then block, but on one line.
An example would be:
In this example, y would be "howdy".
You can read ternary operations as
y = ( comparison ) ? if it's true, use this value : otherwise, use this value ;
This is a very simple example, but you can see the power behind this.
An example in jQuery could be...
Again, this is a very simple example, but you get the point.
One word of advice, though: never use ternary operations if the values to be set are true/false:
Instead, just use the comparison:
About Me

- Matthew Maxwell
- Experienced Web Developer using C#, ASP Classic (VBScript) and ASP.NET, MySQL, T-SQL, and other SQL variants, JavaScript (W3Schools Certified and very well versed in jQuery and learning Dojo), and XML. Heavy interest in JavaScript, framework creation on various language platforms, and keeping up with the best industry-accepted practices.
Blog Archive
Showing posts with label beginning javascript. Show all posts
Showing posts with label beginning javascript. Show all posts
Tuesday, January 26, 2010
Subscribe to:
Posts (Atom)