Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How multiple question marks "?" and colons ":" in one statement are interpreted in javascript? (Conditional Operators)

I know that how simple conditional statements are interpreted, like

condition ? expr1 : expr2 

But I wanted to know how such a statement is interpreted?

function arc() {
    ...
    return da >= d3_svg_arcMax ? r0 ? "String1" : "String2" : r0 ? "String3" : "String4";
}

No need to explain this long expression. I just need to know what it means when multiple question marks and colons are used together like in this example.

Thank you

like image 429
Saman Avatar asked Aug 05 '26 18:08

Saman


1 Answers

Javascript is right-associative, so you 'resolve' the ternaries from right to left.

like image 168
Taylor Daughtry Avatar answered Aug 07 '26 06:08

Taylor Daughtry