function test(a,b,c){
a[b]=c%2===0? "Goose": here!!!!!
}
In the case of code like the one above, you must always write something to substitute after ":", but I don't want to substitute anything.
Null and undefined will replace it, so should I use if honestly now?
No operands are optional to use the conditional operator (Reference.
If you don't want the value to change before and after execution, you can replace yourself.
function test(a,b,c){
a[b]=c%2===0? "Goose": a[b];
}
consta=["xue", "xue";
test(a,0,0);
test(a,1,1);
console.log(a);
How about using Logical product
function test(a,b,c){
c%2===0&&(a[b]="Goose";
}
consta=["xue", "xue";
test(a,0,0);
test(a,1,1);
console.log(a);
Since it seems impossible to say that you only do something when the conditions are true with the trinomial operator, I'll use the if statement
© 2024 OneMinuteCode. All rights reserved.