Questions Concepts
GitHub icon

Ternary operators

Ternary operators - language feature

< >
Example from JavaScript, TypeScript:
let i = true ? 1 : 0
Example from Python, Cython:
print(1 if 1 else 0)
Example from C, C++, Objective-C, Tick C:
#include <stdio.h> int main(void) { printf("%d", 1 ? 1 : 0); }
Example from PHP:
<?php echo 1 ? 1 : 0;
Example from Kotlin:
// Since if statements are expressions println(if (true) true else false)
Example from C3:
int foo = x ? 1 : 0;
Example from Speedie:
while printline (1,0)(random[]>0.5)

Languages with Ternary operators include JavaScript, Python, C, C++, PHP, Kotlin, TypeScript, Objective-C, Cython, C3, Speedie, Tick C

Languages without Ternary operators include HTML, XML, JSON, CSS, JSON5, Ion, Jule, JSONiq, JSON with Comments, Superjson, Scroll, Jsonnet, Hocon, Explorer

This question asks: Does the language have ternary operators?

Read more about Ternary operators on the web: 1.

HTML of this page generated by Features.ts

View source

- Build the next great programming language Search Add Language Features Creators Resources About Blog Acknowledgements Queries Stats Sponsor Traffic Traffic Today Day 305 Logout