8

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;
Philip Kirkbride
  • 17,347
  • 30
  • 101
  • 195
JadeAmerica
  • 123
  • 1
  • 1
  • 4

1 Answers1

33

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;
 }
univerio
  • 16,630
  • 1
  • 49
  • 58
Dayan Moreno Leon
  • 4,839
  • 2
  • 19
  • 24