What does && mean in Javascript when it's outside of an if statement? (Context inside) -
this question has answer here:
- what “x && foo()”? 5 answers
i cleaning code on homepage , found 1 of jquery functions had written so:
$(function(){ var hash = window.location.hash; hash && $('[id^=search] a[href="' + hash + '"]').tab('show'); $('[id^=search] a').click(function (e) { $(this).tab('show'); var scrollmem = $('body').scrolltop(); window.location.hash = this.hash; $('html,body').scrolltop(scrollmem); }); }); this particular piece changes tabs on homepage when external link contains hash matches hashes in navigation. hadn't worked snippet in while (this 1 of first things ever did website.) , cannot life of me work out in brain hash && $('[id^=search] a[href="' + hash + '"]') translates to. if think of plain english, be?
it if statement:
if (hash) { $('[id^=search] a[href="' + hash + '"]').tab('show'); } this equivalent to:
hash && $('[id^=search] a[href="' + hash + '"]').tab('show'); if condition evaluates true next statement after && executed.
Comments
Post a Comment