Ternary Operator in different languages

Gunjan
1 min readMay 11, 2020

--

Fascinated by how different languages have subtle differences in how they define similar operators , the ternary operator actually happens to be the one that is very similar in most languages.

DART/Flutter : displayText: _showMessage ? Text('The message') : Text('')

KOTLIN: If is an expression, as in it returns a value , so there is no ternary operator.. more here.

SWIFT : condition ? true_expression : false_expression

JAVASCRIPT : isAuth ? ‘Welcome’ : ‘Please Login’

JAVA: String eval = (price >= 0) ? “PREMIUM” : “FREE”

--

--

Gunjan
Gunjan

No responses yet