When I first started to develop web based applications and used JavaScript I came across some JS code with a ? in it. I didn't know what it was for and Googling "JavaScript ?" didn't help either. Here's a quick summary on how it works
Boolean ? true action : false action
So this:
var x = 2;
if (x > 1)
window.alert('True');
else
window.alert('False');
Becomes this:
var x = 2;
x>1 ? window.alert('True') : window.alert('False') ;
No comments:
Post a Comment