+ 1
What does the question mark mean in js?
I seen codes like this "7" ? "" That might not be valid, but, I seen the question mark inbetween numbers, What does it do or its job?
2 ответов
+ 2
Ginfio are you wondering if the ternary conditional operator then yes they have worked like if else statements.
Syntax: - condition ? expression1 : expression2
“ ? ” means “if”, and “ : “ means “else”
where the condition is the value to be tested/evaluated
expression1 can be value(s) of any type to be executed if the condition is true
expression2 can be value(s) of any type to be executed if expression1 is false i.e fallback value commonly know as ‘else’
var age = 18;
var canDrive = (age >= 16) ? "You're allowed to drive!" : "You should be 16 to drive!";
console.log(canDrive); // "You're allowed to drive!"
Or another example can be nested conditional.
var st1 = true;
var st2 = true;var check = st1 ? (st2 ? "True, Yes!" : "True, False!") : 'False';console.log(check); // True, Yes!
Have some 🍎 🍎 🍎 🍎
0
I want to see this into actual if ("if") statement:
var count=0;
setInterval(function(){
(1?count += 1:0);
pap.innerHTML = count;
},100);