javascript and spread operator as unexpected token

I have strange problem with spread operator. When I use this code in chrome console, it works great:

var obj1 = { food: 'pizza', car: 'ford' }
var obj2 = { animal: 'dog' }

const merged = { 
  ...obj1,
  ...obj2
};

…but when I use it in my project in VSC, I’m getting an error

enter image description here

unexpected token is indicated in ...obj1

Does someone know how to fix that?

3 thoughts on “javascript and spread operator as unexpected token”

Leave a Comment