DEV Community

Dominic
Dominic

Posted on

Scopes and namespace

Namespace is a container that has all the names (of
variables/functions/classes) that you define. You can define same
names in different namespaces. A name or a variable exists in a
specific area of the code which defines its scope. The information
regarding binding between the variables/objects is stored in the
namespace. There are three types of namespaces or scopes.

Built-in These are in-built functions that are available across all
files or modules.

Global The global namespace has all the variables, functions, and
classes that are available in a single file.

Local The local namespace are variables defined within a function.

The scopes are nested, which means that the local namespace is
nested within a global namespace which is nested within built-in
namespace. Each scope has its namespace.

Discussion (0)