Skip to content

add ternary style to javascript.md #56

Open
@kevinbarabash

Description

@kevinbarabash

The preferred ternary style is the following:

  • if it can fit on a single line, put it on a single line, e.g. const color = selected ? 'green' : 'orange'
  • if it can't fit on a single line, put the ? and : at the start of each line, e.g.
const result = reallyVeryLengthConditional
    ? superLongComputationOfPositiveResult()
    : superLongComputationOfNegativeResult();

const style = selected
    ? {
        color: 'green',
        fontWeight: 'bold',
    }
    : {
        color: 'orange',
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions