Can't understand a little bit ... | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Can't understand a little bit ...

Hi ! I can't understand the second line of code . Here it is : var age = 14; var isAdult = (age < 18) ? "Too young": "Old enough"; /*This one*/ document.write(isAdult);

15th Aug 2017, 5:46 AM
Abdusamad Abdurashidkhonov
Abdusamad Abdurashidkhonov - avatar
4 Answers
+ 9
a ? b : c is similar to if (a) { b } else c *** Looking back at the second line, if (age < 18) { isAdult = "Too young"; } else { isAdult = "Old enough"; }
15th Aug 2017, 5:49 AM
Hatsy Rei
Hatsy Rei - avatar
+ 1
Hatsy Is correct. the ? : operator has three components Condition? if true: if false; If condition is true then the part directly after the ? is performed. Otherwise the last part is performed.
15th Aug 2017, 6:34 AM
S C
0
Thanks
15th Aug 2017, 5:51 AM
Abdusamad Abdurashidkhonov
Abdusamad Abdurashidkhonov - avatar
0
thanks
15th Aug 2017, 12:37 PM
Abdusamad Abdurashidkhonov
Abdusamad Abdurashidkhonov - avatar