The below node JS program order of execution is totally different, can anyone explain to me how the execution is happening?
const readline = require('readline').createInterface({
input: process.stdin,
output: process.stdout
});
function getname()
{
let name=""
readline.question('Who are you?', name =>
{
console.log(`Hey there ${name}!`);
readline.close();
});
return name
}`enter code here`
console.log('My name is'+ getname())
output : Who are you?My name is Summer Hey there Summer!
I only got to understand that this code doesn't work in sequence order as Node JS is asynchronous programming language.