How to make a variable not be sharable outside a function?

how to implement that a created variable inside a function can’t be visualized outside the function it self unless you return it.

Using coblocks (I have pro version) so no limits for now.

I came here from web dev and I knew that something like this should work:

function foo() {
   const a = "hello world";
   /* other logic */

console.log(a) // undefined

as you see in web dev is correct, a is scoped inside the foo function and can’t be accessable outside.

other example:

const a = "outside";

function foo() {
   const a = "inside";
   console.log(a) // inside
   /* other logic */

console.log(a) // outside

now that I showed you the idea in real coding, how can we do this in coblocks?

something like this:

RED = should not be readed (I mean also the UI to add variables should not show the name of var like is not created at all)
GREEN = yes should be readed

1 Like

Hi @LAAOUATNI_ANAS variables that are defined are by definition global, function parameters are scoped within its function, I think aslong as you dont set parameter variable it should be unreachable for anything outside of the function.