# 08. BASICS | Conditional Statements in JavaScript

* * *

## `if` statement

```javascript
if (condition) {
    // execute this code if condition is true
}
```

* * *

## `if ... else` statement

```javascript
if (condition) {
    // execute this code if condition is true
} else {
    // execute this code if condition is false
}
```

* * *

## `if ... else if ... else` statement

```javascript
if (condition1) {
    // execute this code if condition1 met
    // don't check for remaining conditions
} else if (condition2) {
    // execute this code if condition1 doesn't met but condition2 met
    // don't check for remaining conditions
} else if (condition3) {
    // execute this code if condition1 & 2 don't met but condition3 met
    // don't check for remaining conditions
} else if (condition4) {
    // execute this code if condition1, 2 & 3 don't met but condition4 met
} else {
    // execute this code if none of the above conditions met
}
```

* * *

## `switch` statement

```javascript
switch (expression) {
  case value1:
    // Code to execute if expression === value1
    break;
  case value2:
    // Code to execute if expression === value2
    break;
  // ... more cases ...
  default:
    // Code to execute if none of the cases match
}
```

![](https://cdn.hashnode.com/uploads/covers/679f94da85491cdb2d8e2e57/26ddc687-df6f-4d8a-a081-adcd871aafa5.png align="center")

* * *

## ternary operator

> Syntax: `condition ? expression1 : expression2`

> If `condition` is true, execute `expression1` else execute `expression2`.

```javascript
(marks >= 33) ? "Pass" : "Fail"
```

* * *

Happy reading!
