Readability of || statements

Posted by Devin G Rhode on Programmers See other posts from Programmers or by Devin G Rhode
Published on 2012-04-10T03:37:22Z Indexed on 2012/04/10 5:43 UTC
Read the original article Hit count: 370

Filed under:
|

On HTML5 Boilerplate they use this code for jQuery:

<!-- Load jQuery with a protocol relative URL; fall back to local if offline -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></scrip>
<script>window.jQuery || document.write('<script src="js/libs/jquery-1.7.2.min.js"><\/script>')</script>

The question is simple, what's more readable:

if (!jQuery) document.write( -local jQuery- );

or

window.jQuery || document.write( -local jQuery- );

© Programmers or respective owner

Related posts about Maintenance

Related posts about readability