Scope is the accessibility of the variables in JavsScript, and there are
two types of scope, 'Global Scope' and 'Local Scope'. The local scope is used
inside of function,for example, my dog name is Scipio and he is belong to me.
I say myself is function and declare my dog name as Scipio, and only person is
able to call him is me not somebody else. If someone call him from outside of the
house he won't answer(I know he would but not in JavaScipt case, haha!). So, the local
scope is not able to access from outside of function.
The global scope is much simple, for example we build a website and it's called
'Hello World' and anyone in the world who has the internet connection, able to
visit this website. So, the global scope is able to acceess from anywhere in JavaScript,
but this is pretty dangerous to use because other people could use same name as well.
It's important to use the local scope more than the glogal scope.
Back to blog menut