Howdy, Stranger!

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

Categories

Conditional Statements

shannongallentineshannongallentine dallasMember Posts: 4

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

Comments

  • B00B00 Member Posts: 112 ✭✭✭

    {} 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)
    document.write(foo);
    foo = 8;
    
    if (foo > bar) {
    document.write(foo);
    }
    bar = 1;
    
Sign In or Register to comment.