Or Equal Operator

# Артем Гуржий (7 years ago)

I was thinking, is there a proposal for or equal operator as in ruby, or is there any sense for doing so? Example:

let a = 1;
let b = 0;
a ||= b;

Would be interpreted as

a = a || b;

PS: Ruby version is

a || a = b;

They are both equal, but for me, it doesn't look like the javascript version of doing this.

# Claude Pache (7 years ago)

Le 4 févr. 2017 à 02:12, Артем Гуржий <artem.gurzhii at gmail.com> a écrit :

Hi, I was thinking, is there a proposal for or equal operator as in ruby, or is there any sense for doing so? Example:

let a = 1;
let b = 0;
a ||= b;

Would be interpreted as

a = a || b;

PS: Ruby version is

a || a = b;

They are both equal, but it doesn't look like the javascript version of doing this.

Older discussions on the topic:

esdiscuss.org/topic/proposing-a-conditional-assignment-or-equals-operator
esdiscuss.org/topic/new-assignment-operators-not-bit-wise-or
esdiscuss.org/topic/please-add-orequal-operator
esdiscuss.org/topic/is-much-needed
esdiscuss.org/topic/operators-and
esdiscuss.org/topic/logical-assignment-operators

—Claude

# Артем Гуржий (7 years ago)

Is there proposal for this?

# kdex (7 years ago)

Not that I know of.

I think It also went down as the "mallet operator" and got supported by babel at some point.