Skip to content

Instantly share code, notes, and snippets.

@sorie
Created August 12, 2021 00:41
Show Gist options
  • Select an option

  • Save sorie/9b47bf24a27bc8671f5a70e371b3f54a to your computer and use it in GitHub Desktop.

Select an option

Save sorie/9b47bf24a27bc8671f5a70e371b3f54a to your computer and use it in GitHub Desktop.

Revisions

  1. sorie created this gist Aug 12, 2021.
    15 changes: 15 additions & 0 deletions ternary-operator.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    //bad code
    function getResult(score) {
    let result;
    if(score > 5) {
    result = 'up';
    } else if (score <= 5) {
    result = 'down';
    }
    return result;
    }

    //good code
    function getResult(score) {
    return score > 5 ? 'up' : 'down';
    }