- 3
Please given me a example of this code, operator: a > b ? alert(a) : alert(b).
And is this code similar to this code ,var isadult =(age<18)?"young ":"old";
2 Respuestas
+ 5
Yes this code is similar.
This code basically shortcut of if else statement.
if a>b is true so alert a
Else condition is false so alert b
+ 3
Yes, it's similar to that code.
variable = (condition) ? statement-1 : statement-2
Also similar too,
if(a > b){
alert(a);
}else{
alert(b);
}
https://www.sololearn.com/learn/JavaScript/1133/?ref=app
https://www.sololearn.com/learn/JavaScript/1149/?ref=app