Closures - Local vs Private?

Hey,

When I read about Closures, it’s often said that we are using Closures to create private variable, that cannot be accessed outside the function.
But isn’t it that this is true for all local variables inside a function? That they cannot be accessed outside the function?

In regards of Closures, what is the difference between a local and a private variable?

Thanks

Except an object isnt a function.
an Object can have a private variable (or member, to be precise).

Functions define variables for the scope of their operation.
Objects define members with permanence lasting the existence of that object.

Perhaps one of the more quintessential articles explains: https://crockford.com/javascript/private.html

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.