Operators ||= and &&=

Edward Lee edilee at mozilla.com
Wed May 6 13:24:37 PDT 2009

On Tue, May 5, 2009 at 1:37 PM, Peter Michaux <petermichaux at gmail.com> wrote:
> I think optional parameters are the nuisance use case that is fueling
> any discussion about a ||= or ??= operator.
There are other uses that are similar, but wouldn't be covered by
default args. Here's one simple example:

let (hash = {}) function get(key) hash[key] ??= 123

Similarly, if APIs use a single object to take optional args instead
of using function args:

// args is a hash with optional keys "str" and "val"
function foo(args) {
  args.str ??= "bar";
  args.val ??= 10;
  typeof_check(args, { str: "string", val: "number" })

So even if there's a better solution for default args than ||= or ??=,
there's still use for the operators.


More information about the es-discuss mailing list