I cannot figure out how to isolate/encapsulate a function so that only arguments and variables made within the function were accessible. For example if I had:
let greeting = "hello there";
function sayStuff(){
console.log(greeting);
}
sayStuff();
Code above would print "hello there" as expected, but I want to make it so nothing used within sayStuff() could come from the outside unless parsed in as an argument. So I want to make it so that sayStuff() threw and error or printed null because greeting is not defined.
I looked into scope and many links and previous posts referred to doing
(function() {
//your code here
})();
as solution, but this was not the case at least with me, when having code:
const untouchableNumber = 5;
(function() {
//your code here
console.log(untouchableNumber);
})();
it still printed 5 even though untouchableNumber was outside of its brackets and not one of the parameters.
Basically speaking I am trying to make function its own thing, and limit what scope it can access and what it can't.