if alternative javascript 1

if alternative javascript

let count === 0 ? "zero" : count;
//this means: if count = 0 then count = "zero"

Here is what the above code is Doing:
1. We’re using the ternary operator to check if count is equal to 0.
2. If count is equal to 0, then we set the value of count to “zero”.
3. If count is not equal to 0, then we set the value of count to count.

The ternary operator is a great way to write a simple if/else statement on one line.

Similar Posts