1const isBlack = false;const text = isBlack ? 'Yes, black!' : 'No, something else.';console.log(text);// "No, something else."
1//This is what is called a 'Conditional operator'
2let result = condition ? value1 : value2
3// ^^ ^^ ^^
4let result = 1 == 2 ? "YES" : "NO!"
5console.log(result) //output: "NO!"
6
7//Basically a short form of an if-else statment
1boolean statement ? true result : false result;
2
3/*
4For example, if we take this if statement:
5*/
6if (a > b) {
7 result = x;
8} else {
9 result = y;
10}
11// can be also writen:
12result = a > b ? x : y;
1voteable = (age < 18) ? "Too young":"Old enough"
2// condition ? if true : if false