filmov
tv
JavaScript Tutorial 19 - Conditional (Ternary) Operator
Показать описание
In this video I will go over Ternary Operator of Javascript. Ternary operator is an operator that has 3 parts. It is basically a shortcut way to write a if statement.
First you provide the condition, then put a Question mark (?) after the question mark, the statement that will be run if condition is true. After these statements, put a colon. After the colon the statements will be run if condition is false.
example
var a = 10;
var b = 10;
(a == b) ? "true" : "false":
if this example above the statement will give "true" since the condition that a is equal to b is true.
First you provide the condition, then put a Question mark (?) after the question mark, the statement that will be run if condition is true. After these statements, put a colon. After the colon the statements will be run if condition is false.
example
var a = 10;
var b = 10;
(a == b) ? "true" : "false":
if this example above the statement will give "true" since the condition that a is equal to b is true.