What is it "?" (question mark) means in javascript?

I am trying to comment on the code that I used from the tutorial but haven’t actually seen it? -mark used in JavaScript ...

This is a small part of the code below:

this.year = (isNaN(year) || year == null) ? calCurrent.getFullYear() : year;
+4
source share
1 answer

What you're talking about is a ternary operator, which is a string conditional statement. To illustrate:

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

equivalently

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

Source: https://habr.com/ru/post/1543638/


All Articles