SyntaxError: await is only valid in async function collection.find code example

Example 1: await is only valid in async function

async function start() {
   ....

   const result = await helper.myfunction('test', 'test');
}

Example 2: Uncaught SyntaxError: await is only valid in async function

//If you are using reduce(), the since the result of the first accumulation loop 
//will be used in the second second loop.so need one more asyc in front of
// reduce parameters:

const sleep = (n) => new Promise((res) => setTimeout(res, n));

const arr = [1, 2, 3];

const asyncRes = await arr.reduce(ASYNC (memo, e) => {
	await sleep(10);
	return (await memo) + e;
}, 0);

console.log(asyncRes);
// 6
//