SyntaxError: Unexpected token "new" when using await new Promise in JavaScript

Solution 1:

It sounds like you aren't in an async function, so await does not get interpreted as a keyword, but as a variable name. If you put the entire initial snippet into an async function, it'll work as expected.

What's going on with

Unexpected token 'new'

and

await is not defined

is that, when you're not in an async function, those words are interpreted as normal identifiers (variable names) - if you switch them out for another placeholder variable name, it makes more sense for why the syntax would be invalid:

foo = questionData.media ? (someVariable new Promise(resolve => {
foo = questionData.media ? (someVariable (new Promise(resolve => {

Neither of those makes sense, and so the parser will give you errors as expected, when you use await when not in an async function.