How to use optional chaining in Node.js 12
Optional chaining is currently not supported in Node.js version 13 and below. It will be supported from Node.js version 14 and most of the browsers as it is moved to Stage 4. Currently, few platforms are supporting it. You can find the list of platforms supporting optional chaining in the given link. You can enable optional using --harmony
flag.
Optional chaining in node v12.13.1
To use a variable property name with optional chaining, you have to use square brackets, just like normal dynamic property access.
let configTrait = overrideBids[traitType]?.[traitValue];
can't use optional chaining (?)
You have to enable this feature as it is not widely supported by applying the --harmony
flag which applies the new ECMAScript 6 features.
According to node.green, optional chaining will be supported starting with Node 14, but will still require the --harmony flag.
Why is optional chaining not working in my Node REPL?
It's only coming for Node 14 under --harmony:
How to use optional chaining in Node.js 12
You can use babel optional chaining plugin if you want this feature in node:
https://babeljs.io/docs/en/next/babel-plugin-syntax-optional-chaining.html
Unexpected token . when using optional chaning ?. syntax when running mocha
Optional chaining is still behind a flag in Node.js v13. It isn't anymore in the latest Node.js (v14.9.0), though it still was in v14.4.0, so it got deflagged somewhere between those two.
Either update to the latest, or to enable it in v13 and earlier versions of v14:
node --harmony-optional-chaining ...
Related Topics
Jquery Get Values of Checked Checkboxes into Array
React - Getting a Component from a Dom Element for Debugging
What Are Alternatives to Extjs
How to Use Node.Js Module System on the Clientside
How to Ungzip (Decompress) a Nodejs Request's Module Gzip Response Body
Node.Js Variable Declaration and Scope
How to Use Cors to Implement JavaScript Google Places API Request
How to Detect Responsive Breakpoints of Twitter Bootstrap 3 Using JavaScript
How to Access Object Property with Invalid Characters
Keycode Values for Numeric Keypad
Access to Es6 Array Element Index Inside For-Of Loop
Group by Array and Add Field and Sub Array in Main Array
How to Replace a Regex Substring Match in JavaScript
How to Ignore User's Time Zone and Force Date() Use Specific Time Zone
How to Access Custom Attributes from Event Object in React
Is It a Good Idea to Learn JavaScript Before Learning Jquery