0
What does this code mean?
var num = 0; console.log(num?"fulse":"true")
4 odpowiedzi
+ 2
İnline if statement
var x0 = 0;
console.log(x0===0?true:false);//true
var x1 = 1;
console.log(x1===1?true:false);//true
var x2 = 0;
console.log(x2?true:false);//false
var x3 = 1;
console.log(x3?true:false);//true
var x4 = 0;
console.log(x4?"✔":"✘");//✘ means false
var x5 = 1;
console.log(x5?"✔":"✘");//✔ means true
//Thank you for your help guys ☺
+ 7
It's called a ternary operator,
0 for false
1 for true
var num = 0
|_____________
⬇️ ⬇️
(false?"false":"true")
The output is just a great way to confuse yourself I wouldn't recommend using these strings if your learning. use...
(num?"condition is true":"condition is false");
+ 3
That is an "inline" if. It checks the condition, and returns either value.
var num = 0; // 0 is the int version of false, anything bigger is true
console.log(num?"false":"true"); // If num is true (which it isn't), return the string "false" to console.log() otherwise "true"
+ 1
D_Stark nice way of displaying it, I gotta try that 😂