Skip to content

Latest commit

 

History

History
55 lines (41 loc) · 895 Bytes

no-ternary.md

File metadata and controls

55 lines (41 loc) · 895 Bytes
title layout edit_link rule_type related_rules
no-ternary
doc
suggestion
no-nested-ternary
no-unneeded-ternary

Disallows ternary operators.

The ternary operator is used to conditionally assign a value to a variable. Some believe that the use of ternary operators leads to unclear code.

var foo = isBar ? baz : qux;

Rule Details

This rule disallows ternary operators.

Examples of incorrect code for this rule:

/*eslint no-ternary: "error"*/

var foo = isBar ? baz : qux;

function quux() {
  return foo ? bar() : baz();
}

Examples of correct code for this rule:

/*eslint no-ternary: "error"*/

var foo;

if (isBar) {
    foo = baz;
} else {
    foo = qux;
}

function quux() {
    if (foo) {
        return bar();
    } else {
        return baz();
    }
}