When to use brackets after if statement JavaScript -


hi how determine when use brackets after if statements. thought should used time have seen brackets not used example:

timers.add(function () {   box.style.top = y + "px";   y += 2;   if (y > 120) return false; 

});

really, should add them readability. can omit them when following statement 1 want include in if block. if have 2 statements after if, second 1 execute after if block done when no brackets present. in code below example 1 set = 5. in example 2 alert fire, hard read. example 3 same 2, easy read.

// example 1     if (5 == 5) = 5;  // example 2     if (5 == 10) = 5; alert("hello");  // example 3     if (5 == 10) {        = 5;      }     alert("hello"); 

Comments

Popular posts from this blog

visual studio - vb.net filter binding source by time -

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -