What is the difference of an `if` statement that has an {open-close} brackets, and without {open-close} brackets

by Jesper Martinez   Last Updated May 22, 2020 18:04 PM - source

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 :)



Answers 1


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).

Éric
Éric
May 22, 2020 17:28 PM

Related Questions



Javascript problem

Updated April 28, 2015 21:01 PM