Can anyone explain what is happening in this bit of Javascript?
<p>I was looking through a jQuery smooth-scrolling tutorial, and trying to figure out how it worked, when I hit this line of code:</p>

<pre><code> $target = $target.length &amp;&amp; $target || $('[name=' + this.hash.slice(1) +']');
</code></pre>

<p>I can't figure out what it does. It looks like the guy is assigning a string to a variable, but it also kinda looks like he's testing that variable. And I don't understand the use of &amp;&amp; and || here. Can anybody explain this?</p>

<p>Thanks!</p>

<p>EDIT: Wow! What a response! This is taking a bit for me to understand, though - I will have to print this out or something and work on it. Once I understand what's going on, I'll be able to pick the answer that helped me the most. In particular, this bit:</p>

<pre><code>if ($target.length &amp;&amp; $target) {
$target = $target;
</code></pre>

<p>is stymying me. How does the program know to assign $target to $target? Does the operation assign $target to the first reference to itself (the left side of the equals sign), or to the second reference to itself (the right side, after the &amp;&amp;)?</p>
