Skip to content

suggestion: Null-Coalescing Operator  #128

@gavinengel

Description

@gavinengel

This syntax seems to be a more compact ternary operator, is that right?

// spider syntax:
var name = somethingElse;
name = name ?? 'default name';

If so, may I suggest a slightly different form? Per a suggestion here, I re-write the above which checks a variable and defaults it if the variable is empty/false:

// suggested formats, all of which are the same
var name = somethingElse;
name = name ? name : 'default name'; // traditional ternary
name = name ?: 'default name'; // shortened ternary <-- this looks better to me
name = name || 'default name'; // just like the one above
name = name ?? 'default name'; // spider syntax
name ?= 'default name'; // really short ternary  <-- I also like this

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions