nested if else vs logical operators in JavaScript Posted January 22, 2015 I have 3 variants of code that all do the same thing. Is there a best practice for choosing? Is it just appearance and ease of following or is there a technical reason to use one over the other? /*if ( ($(window).width() < 535) || ($(window).height() < 700) ) { if (scrollTop > stickyNavTop) { jQuery('body').addClass('stickynav'); } else { jQuery('body').removeClass('stickynav'); } } else { jQuery('body').removeClass('stickynav'); } if ( (scrollTop > stickyNavTop) && ( (($(window).height() < 700) || ($(window).width() < 535)) )) { jQuery('body').addClass('stickynav');} else { jQuery('body').removeClass('stickynav'); } if ( ((scrollTop > stickyNavTop) && ($(window).height() < 700)) || ((scrollTop > stickyNavTop) && ($(window).width() < 535)) ) { jQuery('body').addClass('stickynav');} else { jQuery('body').removeClass('stickynav'); } Cheers
nested if else vs logical operators
in JavaScript
Posted
I have 3 variants of code that all do the same thing.
Is there a best practice for choosing?
Is it just appearance and ease of following or is there a technical reason to use one over the other?