Questions tagged [nullish-coalescing]

34 questions
-1
votes
1 answer

How can I get eslint to accept the nullish-coalescing assignment?

The "nullish-coalescing assignment" operator, ??=, is a relatively recent introduction to JavaScript; but not all that recent... and yet, eslint, even newer versions like 8.38.0, seem not to recognize it - and yields a syntax error about the…
einpoklum
  • 118,144
  • 57
  • 340
  • 684
-1
votes
1 answer

Caveats of using the nullish coalescing operator (??) to check for the existence of a key in an object?

With the nullish coalescing operator (??), one is tempted to use it for specifying defaults for non-existent object keys, as suggested in an answer here, e.g.: let a = foo.bar ?? 'default'; However, it's alternatives in this case (mainly in and…
vasilyrud
  • 825
  • 2
  • 10
  • 18
-1
votes
1 answer

Where to use nullish operator in javascript?

function test(val) { const hasError = val ?? true; if (hasError) { //error handling... } else { //do something... } } test(null) //error handling... test(undefined) //error handling... test('text') //error…
-2
votes
1 answer

Javascript nullish coalescing returns "f { [native code] }"

I am getting an unexpected result while trying to use nullish coalescing operator on a return value that might be an array or might have an array as a child const storedKeys = await getStoreKeys(); let keys = storedKeys.keys ?? storedKeys; …
1 2
3