Syntax error for using the JS ?. undefined check

hello i am trying to build Vue+gridsome website for the first time…

on Netlify build i get thie error…
3:19:52 PM: title: event?.title || noVal,
3:19:52 PM: ^
3:19:52 PM: SyntaxError: Unexpected token ‘.’

so the ?. js syntax to check if undefined then use X…

I’m assuming this is what you want to do: You want to set the title as event.title if it’s defined or noVal if it’s not. If I’ve understood it correctly, the syntax should be title: event.title ? event.title : noVal.

title: event?.title || noVal,

this code is working fine on my local machine… and in many other places on the app i am using the same pattern…
so maybe its got to do with the JS version…

like in here
How the Question Mark (?) Operator Works in JavaScript (freecodecamp.org)

JS is executed by browser, not Netlify. There’s no JS version on Nelify.

The closest you can get is by checking if the Node version on your local machine and Netlify matches or not and set it accordingly.

2 Likes