loading...

re: JavaScript: Latest Stage-4 features VIEW POST

TOP OF THREAD FULL DISCUSSION
re: Are you sure about ||= and the other operators? I thought that a ||= b actually meant a = (a || b) -- am I wrong?
 

Motivation

Convenience operators, inspired by Ruby's. We already have a dozen mathematical assignment operators, but we don't have ones for the often used logical operators.

function example(a) {
  // Default `a` to "foo"
  if (!a) {
    a = 'foo';
  }
}

A proposal to combine Logical Operators and Assignment Expressions:

// "Or Or Equals" (or, the Mallet operator :wink:)
a ||= b;
a || (a = b);

github.com/tc39/proposal-logical-a....

Code of Conduct Report abuse