Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jeremiahjstanley/58a993616e987294d01a973b3a0cec1a to your computer and use it in GitHub Desktop.
Save jeremiahjstanley/58a993616e987294d01a973b3a0cec1a to your computer and use it in GitHub Desktop.

Conditionals

Conditional let us determine when we do what

Using conditionals allows us to protect code from executing until the proper conditons are met.

Think of conditionals a way of putting a wall around a walled city. Your city has a gate, but you hold the power to open that gate from the right people

Let's look at an example:

var age = 18

if (age < 21) {
  console.log('Sorry kid, I can't serve you')
}

In this example, a comparing two number, if age is less than (<) 21 we excute the console.log within the brackets. In the age the expression age < 21 evaluates to true.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment