0

What does this code mean?

var num = 0; console.log(num?"fulse":"true")

17th Aug 2019, 11:58 AM
Safaa Alnabhan
Safaa Alnabhan - avatar
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 ☺
17th Aug 2019, 2:15 PM
Safaa Alnabhan
Safaa Alnabhan - avatar
+ 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");
17th Aug 2019, 12:05 PM
D_Stark
D_Stark - avatar
+ 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"
17th Aug 2019, 12:04 PM
Paul Grasser
Paul Grasser - avatar
+ 1
D_Stark nice way of displaying it, I gotta try that 😂
17th Aug 2019, 12:06 PM
Paul Grasser
Paul Grasser - avatar