---
description: https://stackoverflow.com/questions/7757549/multiple-ternary-operators
---

# how to use multiple ternary operator in javascript, ?:, ?? (ok)

### 1. test.html

<figure><img src="https://2726517656-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M1E4Gk2ppVKb4olmnun%2Fuploads%2FIw2MxGdZQX8Pllbwo5VM%2Fimage.png?alt=media&#x26;token=2a8879a0-7bc4-4418-81a9-af0c214d3fcd" alt=""><figcaption></figcaption></figure>

```
<script>
	let area = 1;
	var icon = (area == 1) ? "icon1" : (area == 2) ? "icon2" : "icon0";
	console.log(icon);
</script>
```

### 2. test.html

<figure><img src="https://2726517656-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M1E4Gk2ppVKb4olmnun%2Fuploads%2Fn7lNdAlloVvg5xHN49kn%2Fimage.png?alt=media&#x26;token=36bd6f9f-f9c9-4ea6-92e6-886886d6571e" alt=""><figcaption></figcaption></figure>

```
<script>
	let area = 2;
	var icon = (area == 1) ? "icon1" : (area == 2) ? "icon2" : "icon0";
	console.log(icon);
</script>
```

### 3. test.html

<figure><img src="https://2726517656-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M1E4Gk2ppVKb4olmnun%2Fuploads%2FtLzao0T4QGw48txByBTA%2Fimage.png?alt=media&#x26;token=4a5a0151-00bc-4a6a-a690-94ff1d9cb874" alt=""><figcaption></figcaption></figure>

```
<script>
	let area = 3;
	var icon = (area == 1) ? "icon1" : (area == 2) ? "icon2" : "icon0";
	console.log(icon);
</script>
```
