JavaScript ternary operator example with functions
<p>I am using jQuery 1.7.1</p>

<p>I am just starting to use the JavaScript ternary operator to replace simple if/else statements. I have done so successfully in several places.  I was surprised when I successfully made something else work when I thought for sure it wouldn't, but I tried anyway.</p>

<p>Here's the original statement:</p>

<pre><code>function updateItem() {
    $this = $(this);
    var IsChecked = $this.hasClass("IsChecked");
    if (IsChecked == true){
        removeItem($this);
    } else {
        addItem($this);
    }
}
</code></pre>

<p>Here's the same function using the ternary operator:</p>

<pre><code>function updateItem() {
    $this = $(this);
    var IsChecked = $this.hasClass("IsChecked");
    (IsChecked == true) ? removeItem($this) : addItem($this);
}
</code></pre>

<p>I was surprised because all of the examples I saw being used were merely setting variables like this:</p>

<pre><code>x = (1 &lt; 2) ? true : false;
</code></pre>

<p>My question is whether this is "normal" use and will it work in most versions of JavaScript? Where will it fail?  Are there other less obvious uses for it?</p>

<p><strong>UPDATE -- Thanks for the "real world" advice!!!</strong></p>

<p>I am using this as my function:</p>

<pre><code>function updateItem() {
    $this = $(this);
    $this.hasClass("IsChecked") ? removeItem($this) : addItem($this);
}
</code></pre>
