Code Lab is in development. New lessons and improvements are on the way. Progress can be deleted.
Loading…
Code Lab is in development. New lessons and improvements are on the way. Progress can be deleted.
Loading…
Code Lab is in development. New lessons and improvements are on the way. Progress can be deleted.
JAVASCRIPT FOUNDATIONS / CHAPTER 01 / Learn / LESSON 10
Tenth class. A variable created inside a function lives only there — that is scope. Outside, you cannot see it.
So functions take parameters and return with return, instead of leaning on “global” names everywhere. Code stays clearer and safer.
Mini example:
function label(n) { const text = "left"; return text; } console.log(label(1));
Common mistake: expecting to use an inner const outside the function — you get ReferenceError.
Inner variables are invisible outside — send values out with return. The harness calls remaining(900, 400) → 500.
JS CONSOLE IDLE
›