JavaScript 'Nullish coalescing operator' throwing an Error if it is null?

109 views Asked by At

I was hoping for a very concise

video = document.querySelector('#video') ?? throw new Error("Unable to find #video");

But that gives me a "Uncaught SyntaxError: Unexpected token 'throw'"

Is there an easy way to natively do this with the ?? or ?. operators?

0

There are 0 answers