Use-Ternary-Operator
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.
Sourcery rule id: use-ternary-operator
Section titled “Sourcery rule id: use-ternary-operator”Description
Section titled “Description”Replace if statement with ternary operator
Before
Section titled “Before”if (cond) { var x = 1} else { var x = 2}var x = cond ? 1 : 2;Explanation
Section titled “Explanation”The ternary operator is a simpler and more elegant way to write conditional assignments to a variable than the long form.