0
 if (oldPresenter?.userId !== currentPresenterId) {
      return setPresenterInPodReqMsg(setPresenterPayload);
    }

I got syntax error in this snippet running with Node.js but working for other people. I need explanation if it is correct JS syntax.

4
  • SyntaxError: Unexpected token . Commented Dec 23, 2020 at 20:28
  • Put it in your question, please. And be specific. Errors usually point to a specific line or character. Commented Dec 23, 2020 at 20:30
  • Probably you aren't running a new enough version of nodejs to support the ?. feature. Commented Dec 23, 2020 at 20:30
  • You need node 14 or greater to use the safe navigation/chaining operator Commented Dec 24, 2020 at 2:38

3 Answers 3

2

You are using optional chaining. It is in Stage 4. Optional chaining is supported in node version v14.2.0 or higher!

Sign up to request clarification or add additional context in comments.

1 Comment

Here is the reference for the operator with browser compatibility, for those interested. I wasn't aware it's in development!
1

?. is called the optional chaining operator. On the last versions of node it's valid syntax.

Comments

0

This javascript syntax will be reported incorrect for any Node version < 14. To be able to use this format ( specifically the ?. optional chaining syntax ), first check your node version using node -v on your commandline, and if < 14, then update to a Node version >=14.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.