---
id: 65e97293484dd50f720e6ff1
title: Learn Data Types and Conditionals Lesson L
challengeType: 15
dashedName: learn-data-types-and-conditionals-lesson-l
---
# --description--

Another way to compare conditional statements would be the ternary operator. The ternary operator is a shorthand way of writing an `if-else` statement. It is used to evaluate a condition and return a value based on the result of the condition. The syntax of the ternary operator is as follows:

```javascript
let result = condition ? value1 : value2;
```

In the above example, if the condition is true, the value of `result` will be `value1`. Otherwise, the value of `result` will be `value2`.

Ternary operators are often used to assign a value to a variable based on a condition. They are also used to return a value based on a condition.

# --questions--

## --text--

What is the value of the `result` variable if the value of the `condition` variable is `true`?

```javascript
let condition = true;
let result = condition ? "option 1" : "option 2";
```

## --answers--

`"option 2"`

---

`"option 1"`


## --video-solution--

2
