Skip to content

Invert-Ternary

Documentation Index

Fetch the complete documentation index at: https://docs.sourcery.ai/llms.txt

Use this file to discover all available pages before exploring further.

Invert ternary operator to remove negation

const beverage = !too_young ? 'Beer' : 'Juice';
const beverage = too_young ? 'Juice': 'Beer';

Negated conditions are more difficult to read than positive ones, so it is best to avoid them where we can. By inverting the ternary condition and swapping the expressions we can simplify the code.