Logical nullish assignment (??=) gives an error in Visual Studio Code

Logical nullish assignment is giving SyntaxError: Unexpected token '??=' in the Visual Studio Code. Is there any solution for this error?

I am trying this code;

const a = { duration: 50 };

a.duration ??= 10;
console.log(a.duration);
// expected output: 50

a.speed ??= 25;
console.log(a.speed);
// expected output: 25

1 thought on “Logical nullish assignment (??=) gives an error in Visual Studio Code”

  1. Try adding this or similar to your eslintrc.json file (or wherever you have your eslint options):

    {
      ... other options
    
      "parserOptions": {
        "ecmaVersion": 2020,   <== you need this or a similar more recent option
        "sourceType": "module"
      },
      ... other options
    }
    
    Reply

Leave a Comment