Not sure if this is the correct place to post, But looking at the HTML5 boilerplate I have…
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.js"></script>
<script>window.jQuery || document.write('<script src="_includes/js/libs/jquery-1.6.2.min.js"><\/script>')</script>
Now I’ve read the second script is a fall back for if the first is down, but how?
I always thought || was an OR operator and to me it just looks like it says when the page loads write an old jQuery lib to the page?
The second half of the
||operator is only evaluated if the left hand side is “falsey”. This is known as “short circuit evaluation” *So when
window.jQueryisundefined, it does thedocument.write().*
true || x == true, regardless of x’s value, so a short circuit||operator giventruefor its left hand operand will skip evaluating the right hand of the expression since it doesn’t change the result.Conversely
false && x == false.