Skip to content

Commit

Permalink
new post
Browse files Browse the repository at this point in the history
  • Loading branch information
loverajoel committed Feb 2, 2021
1 parent d51b30a commit 89a8d07
Showing 1 changed file with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
layout: post

title: What is the JavaScript ternary operator?
tip-number: 81
tip-username: loverajoel
tip-username-profile: https://www.twitter.com/loverajoel
tip-tldr: The method received as an argument for the promise.

categories:
- en
- javascript
---
The ternary operator is a shortcut for the `if` statement. It consists of three operands; a question mark, a condition, and an expression to execute if the condition is true, followed by a colon and another expression to execute if it’s false.

```js
let age = 26;

// condition ? expression if true : expression if false
let drink = (age >= 21) ? "Beer" : "Juice";

console.log(drink); // "Beer"

// Equivalent to:
let drink;
if ((age >= 21)) {
drink = "Beer";
} else {
drink = "Juice";
}

console.log(drink); // "Beer"
```

0 comments on commit 89a8d07

Please sign in to comment.