Skip to main content

JavaScript Ternary Operator




In this video i discussed about ternary operator with example using JavaScript

Code:
<script language="javascript">


var age = prompt("Enter your age");

if(age>60){
//document.write("You are old");

}
else {

//document.write("You are not old");
}

//condition?true:false
var res = (age>60)?"You are old":"You are not old";
alert(res);

</script>

Comments