Nullish Coalescing in ScriptLab

67 views Asked by At

My function parameter should accept a 0 or false value for an optional parameter, so I am using the ?? operator instead of the || operator for default value assignment to avoid a valid value overwritten with the default value.

So, here is the sample function code:

function myfunction(param1: number, param2?: number): number 
{
  param2 = param2 ?? 1

  console.log(param2)

  return param2
}

However, even though the function works without problems, the ScriptLab editor reports a syntax error.

ScriptLab syntax error warning

Is this a known ScriptLab bug?

Thanks.

1

There are 1 answers

0
Eugene Astafiev On

Sounds like a bug, but the ScriptLab add-in is available with a source code (open source project). You can find the add-in's source code available publicly on GitHub - https://github.com/OfficeDev/script-lab. So, you may try debugging it to find the cause. Even if it is maintained by the Office team, nobody can stop you from adding or fixing things.