Skip to content

Instantly share code, notes, and snippets.

@codingedgar
Created January 4, 2021 22:03

Revisions

  1. codingedgar created this gist Jan 4, 2021.
    22 changes: 22 additions & 0 deletions logicalOrOperator.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    console.group('Logical OR assignment (||=)');

    const a = { duration: 50, title: '' };

    a.duration ||= 10;
    console.log(a.duration);

    a.title ||= 'title is empty.';
    console.log(a.title);

    console.groupEnd();

    /*
    Console:
    Logical OR assignment (||=)
    50
    title is empty.
    */

    // Other usefull example can be:
    document.getElementById('lyrics').textContent ||= 'No lyrics.'