Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
30
rated 0 times [  34] [ 4]  / answers: 1 / hits: 36785  / 10 Years ago, sat, june 7, 2014, 12:00:00

I'm trying to comment out code that I used from a tutorial but haven't actually seen a ?-mark used in JavaScript...



This is a small part of the code below:



this.year = (isNaN(year) || year == null) ? calCurrent.getFullYear() : year;

More From » javascript

 Answers
8

What you are referring to is the ternary operator which is an inline conditional statement. To illustrate:



 this.year = (isNaN(year) || year == null) ? calCurrent.getFullYear() : year;


is equivalent to



if(isNaN(year) || year == null){
this.year=calCurrent.getFullYear()
}
else{
this.year=year;
}

[#70673] Thursday, June 5, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kenyamelinad

Total Points: 339
Total Questions: 85
Total Answers: 116

Location: Marshall Islands
Member since Sun, Aug 29, 2021
3 Years ago
;