Higher_order_function

function creatgreeter(name)
{
firstname = name.split(" ")[0];
function greeter()
{
return "Hello " + firstname
}
return greeter;
}

let johncreater = creatgreeter(“John Doe”);
let harrycreater = creatgreeter(“Harry potter”);

console.log(johncreater());
console.log(harrycreater());

Expected output is:
Hello John
Hello harry

output is:
Hello Harry
Hello Harry

Variables defined without var/let keyword become global variables.
So when you set the value of firstname for the 1st time, you are actually declaring a global variable and assign ing the value.
That explains the program behavior.

Ok, right
There is another program using new keyword

let soo = “Hi this is Manav Kumar”

function fun()
{
this.p = “This is something”
console.log(this == global)
console.log(global.soo)
return 10;
}

fun()

console.log(this == global)

why does this outside the function is not equal to the global
And also inside the function if it is global why does it not able to access the outside variables available inside the scope
??

Read this, you will get clear understanding regarding how node handles exports and global variables.