Local and Global
Scope is the region of a program where a name can be seen. A variable created inside a function is local to it. It is born when the function is called and it dies when the function returns. Code outside the function cannot see it at all.
A variable created at the top level of a file is global. Every function in that file can read it.
✦ Why this is a feature, not an obstacle
Local scope means you can name a variable `total` inside twenty different functions and none of them collide. Without it, every name in a large program would have to be unique. Scope is what makes code composable.
Mark this lesson complete
Signed in, your progress follows you to every device.