if..else Statement

if..else Statement

  • Used when evaluating between just two choices

  • These are great for “either or” situations

  • You do not specify a condition for the “else” clause

// if..else statement

if (condition) {

  code to run if condition is true

} else {

  code to run if the above condition is NOT true

}

// run some other code

Example

const yearOfBirth = 2001

if (yearOfBirth <= 2002) {

  console.log('you will be old enough to vote in 2020')

} else {

  console.log('Sorry, you will not be old enough to vote next year')

}

JS Bin on jsbin.com