Logical assignment operators in JavaScript combine Logical Operators and Assignment Expressions.
//"Or Or Equals"
x ||= y;
x || (x = y);
...
For further actions, you may consider blocking this person and/or reporting abuse
Nice work, thank you for sharing.
I understand better the ??= example with a console.log and changing assignment here: repl
So opts.dog ??= 'bow'; means: if opts.dog is not set, assign bow
Hi! I'm not sure -- isn't x ||= y the same as x = x || y ? This is aligned to how other operators (+=, *=, etc.) do work.
x ||= 1
would meanx || (x = 1)
Aren't the two expressions
x = x || y
andx || (x = y)
equivalent?Nice work, @hemanth ! These will be super handy
Nice work on a very useful addition to the language. Great to see you stuck with it.
Very useful new features! Looks like you got the variables mixed up in the examples:
Should be
... unless I got this all wrong?
True, fixed it. I was trying to bring in another variable.
Imho, it would be important to emphasise on ??= checking for null and undefined, while ||= checking for falsy values. Could save some bugs :D
Same as:
0 || 42 // 42
0 && 42 // 0
0 ?? 42 // 0
Yup, so dev.to/hemanth/vs-2ke7