---
title: "JavaScript: Conditional Code"
date: 2013-02-02
description: "You can start building more complex JavaScript statements by using conditional code. The conditional code allows you to ask if a condition is met. If the condition is met, a..."
canonical_url: https://idratherbewriting.com/conditional-code-javascript/
---
# JavaScript: Conditional Code
You can start building more complex JavaScript statements by using conditional code. The conditional code allows you to ask if a condition is met. If the condition is met, a certain code block is run. If the condition isn't met, a different code block is run. The answer to the condition must always be a yes or no answer.

## Conditional Code Format

Here's the format of the conditional code:

The statement begins with `if` followed by a condition in parentheses. After the condition, the code block is run. Code blocks are contained within curly braces `{ }`. The `else` means "if the previous condition isn't met, do this instead," or more simply, "Otherwise."

Here's an example with some information:

## Conditional Operators

In the condition statement, you can use a variety of operators to ask questions:

## Equals Signs

Note that the equals operator is two equals signs `==`, not one. When you set the value of a variable, you use one equals sign `=`. One equals sign means "assign as" whereas two equals signs means "equals".

There's also a triple equals sign `===`, which means "is strictly equal to." This is a more formal way of checking conditions. For example, if you have a variable that's a number, such as `var a = 10`, and another variable that's a string, such as `var a = "10"`, the two variables are different types of variables and therefore aren't "strictly" equal, even though they're the same.