DEV Community

Discussion on: Use JavaScript Optional Chaining, Today!

Collapse
 
njugunapm233 profile image
njugunapm233

console.log(restaurant.openingHours[tue] ? .open);
on saving I get a gap between . and ? as seen above.
The on console this is the error.
Uncaught SyntaxError: Unexpected token '.'

Collapse
 
ender_minyard profile image
ender minyard

Try removing the spaces between . and ?.

console.log(restaurant.openingHours[tue] ? .open); //Error: expected expression, got '.'
console.log(restaurant.openingHours[tue]?.open);  // Evaluates expression
Enter fullscreen mode Exit fullscreen mode
Collapse
 
njugunapm233 profile image
njugunapm233

The error occurs when I save the file.

Collapse
 
njugunapm233 profile image
njugunapm233

"eslint.autoFixOnSave": true,

the above code seems to be deprecated.
kindly assist.

Thread Thread
 
ender_minyard profile image
ender minyard

Can you disable ESLint? ESLint may be causing the error.