Skip to main content

If conditions


  • function definition function getVotingMessage(age)
  • the opening curly brace { corresponding to the function (on the 1st line)
  • the if condition if (age >= 18)
  • the opening curly brace { corresponding to the if condition (on the 2nd line)
  • the return "You are allowed to vote"
  • the closing curly brace } corresponding to the if condition (the closing curly brace on the 4th line closes the one opened on the 2nd line)
  • the closing curly brace } corresponding to the function (the closing curly brace on the 5th line closes the one opened on the 1st line)
function getVotingMessage(age) {
if (age >= 18) {
return "You are allowed to vote"
}
}

Note: An Opening brace will always need to be closed. Using Prettier and some sort of bracket syntax colorizer will be a good idea for this.
image.png

  • Closing curly braces are often accidentally omitted, especially when there's an if condition inside a function.
  • Every time you open a curly brace, remember that it needs to be closed.
  • You can move the cursor to a curly brace, and the text editor will highlight the matching one.