question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Optional chaining obj?.[expr]

See original GitHub issue

The obj?.[expr] syntax of optional chaining don’t work as expected:

Input

let nestedProp = obj?.['prop' + 'Name'];
let arrayItem = arr?.[42];

Expected (no change)

let nestedProp = obj?.['prop' + 'Name'];
let arrayItem = arr?.[42];

Actual

Space between . and [

let nestedProp = obj?. ['prop' + 'Name'];
let arrayItem = arr?. [42];

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

0reactions
h0rn3z0rcommented, Jan 26, 2021

@bitwiseman This issue is not fixed. The latest js-beautify still inserts an extra space character after the optional chaining operator.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Optional chaining (?.) - JavaScript - MDN Web Docs - Mozilla
The optional chaining (?.) operator accesses an object's property or calls a function. If the object accessed or function called is ...
Read more >
How to Use Optional Chaining in JavaScript - freeCodeCamp
Optional chaining is a safe and concise way to perform access checks for nested object properties. The optional chaining operator ?. takes ...
Read more >
JavaScript Optional Chaining Operator (?.)
In this tutorial, you'll learn about the optional chaining operator (?.) that simplifies the way to access values through connected objects.
Read more >
How to Use JavaScript Optional Chaining - Dmitri Pavlutin
Optional chaining accesses properties from deep of nested objects without prop existence verification and intermediate variables ...
Read more >
Optional chaining (?.) - JavaScript
The value of obj.first is confirmed to be non- null (and non- undefined ) before ... Using optional chaining with function calls causes...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found