Conditional Statements

Why do we need conditional {} using an IF statement?
I ran it with and without and it worked both ways.


  • {} is not a conditional, curly brackets delimit a code block. If there is only one code line after for, while, if you can omit them but for readability purpose I suggest you always use them.
    Here's an example. What if indentation got messed up, which of the below is more clear?

    var foo = 3;
    var bar = 5;
    if (foo > bar)
    foo = 8;
    if (foo > bar) {
    bar = 1;
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


In this Discussion