Inline IF statement

Publication: 22 of March, 2020
The inline if statement or Conditional (ternary) operator like it´s call as well it´s a very useful statement for the simpleness compare to the normal if statement like if (variable === true) { ...., it´s the only Javascript operator that takes 3 operands. That is a condition followed by a question mark ?, an expression to execute if the condition is true followed bi a colon :, and then an expression to execute if the condition is false, see example below.

var number = 12

var example = (number === "12" ? "cat" : "dog"); 

In the example above we can see that the variable number is set to 12 and in the variable below has the if operator, because the variable number is 12 the value for the second variable will be cat but if we change the value of the first variable to any other thing but 12 , the value of the variable will be dog, because it will not met the condition.
It was a pleasure and happy coding!

Copyright Luis Gonzalez 2021