Optional chain operators are included in the specification: developer.mozilla.org/zh-CN/docs/…

Benefits: Easy to write and read

// Use effect:
const obj = {a: {b: {c: 1}}}/ / we need to get c, compatible writing a && a. && A.B.C or (a | | {}). (b) | | {}). C
// With optional chains and Babel parsing, you can write: a? .b? .c
console.log(a? .b? .c)Copy the code

Configuration method

// In package.json, install dependencies
{
  "devDependencies": {
    "@babel/core": "^ 7.12.9", (7.0The following Babel packages need to be deleted)"@babel/plugin-proposal-optional-chaining": "^ 7.12.7"(Depend on Babel7.0Above)"babel-loader": "^ 8.2.2". }... }// Create a new file ".babelrc.js" (in the same directory as package.json)
{
  "plugins": [
    "@babel/plugin-proposal-optional-chaining"]}Copy the code