-1

if statement has an open {} close brackets

  if(example){
      return example;
  }else{
      return example;
  }

if statement without open {} close brackets

  if(example)
      return example;
  else
      return example;

Can anyone explain to me about the pros and cons of using them? Thanks in advance :)

2
  • I tried to migrate this to Stack Overflow where it belongs, but the migration failed. Programming questions are better suited for Stack Overflow than here. May 22 '20 at 17:32
  • @StephenOstermiller I apologize for my question, that's why I tried to ask here because I could not ask there anymore :( sorry for that kind of stuff. May 22 '20 at 17:39
2

There is no difference in PHP or JavaScript for example; except that, with the brackets, it is easier to add instructions later without breaking your code (you are less likely to forget to add the brackets that become mandatory).

1
  • 3
    also, personally, I find it a bit easier to visualise the start and end of the if or the else.
    – Steve
    May 22 '20 at 23:27

Not the answer you're looking for? Browse other questions tagged or ask your own question.