Logical AND operator and template literals

github logo ・1 min read

Hello all,

I would like to know your opinion on if this syntax is considered normal and legit. Especially that part of using template literals in order to call some functions in order to assign new value to previously declared variable.

const page = await report.page('TestPage');

let visual;
page && `${visual = await page.visual('TestVisual').then(/*... do some stuff... */).catch(err => console.log(err))}`;

let data;
visual && `${data = visual.exportData().catch(err => console.log(err))}`

It works, and I find it pretty much nice. However maybe there are some unknown for me drawbacks which you could point me out.

Thank you!

twitter logo DISCUSS (3)
markdown guide

This is not the right way.... You're mixing async/await and promises and the structure isn't the nicest :)

try {
const page = await report.page('TestPage')
const visual = await page.visual('TestVisual')

// do whatever you want with visual

const data = await visual.exportData()

// do whatever you want with data

} catch (err) {



You're welcome, let me know if you have any follow up questions

Classic DEV Post from Feb 11

The 7 Most Popular DEV Posts from the Past Week

A round up of the most-read and most-loved contributions from the community this past week.

fuji profile image