JSFiddle - React, Tailwind, and code Playground

by Uriel Zarnihchi

JavaScript

/*
Description: 

Here we use a chain of function with a "await" and one without "await",
When we have the "await" then we make the coments by the order of the lines, 
but when the root function doesn't use the "await" then only this function lose the order of the 
lines, but other function in the chain still will keep this order bexause they have the "await".

Note - when a functiion doens't return a Promise but an undefined then the "awaint" doesn't make 
anything and all the calls goes by the lines orders, no matter with ior without "await"
*/

const sayHi = () => {
	return new Promise(resolve => {
  	setTimeout(() => {
    	console.log('Say Hi');
    	resolve();
    }, 2000);
  });
}

/*
const sayHi = () => {
	console.log('say Hi');
}
*/

const callSayHi = async () => {
	console.log('Call Say Hi');
  await sayHi();
  console.log('Call Say Hi - finished');
}

const withAwait = async () => {
	console.log('withAwait');
	await callSayHi();
  console.log('withAwait - finished');
}

const withoutAwait = () => {
	console.log('withoutAwait');
	callSayHi();
  console.log('withoutAwait - finished');
}

// setTimeout(async () => {await withAwait();}, 0);
setTimeout(() => {withoutAwait();}, 0);