Lesson 4
Scope
Scope can be a tricky concept to master. At its heart, it's about where a variable (or function, or other element) can be access. For example. Think of an intercom system in a school vs a radio. They both can play music. The office can play music that everyone can hear. Any room in the school can both hear the music. But the radio that I play in my room, can (at normal volume) only be heard in my room. If you want to hear what I'm playing, you have to be in my room. But if you want to hear what the office is playing, you could be anywhere in the school. That's what scope is about. If you create a variable inside of a block of code, you can only access the variable in that block. Think radio. If you create a variable outside the block you can access it anywhere in the code. Think intercom. These two types of scope in JavaScript are called local (radio) and global (intercom).
Activities
- Complete the lessons for Scope in Codecademy. Show your teacher your checkmark for completion. There is no checkpoint for this lesson.
- Update your portfolio from Web Design 1 to include the four lessons from JS so far. Things to remember:
- Put this on the scripting page.
- Include a short paragraph about each lesson so far.
- Link to your checkpoints as well as your Rock, Paper Scissors game.
- Make certain your work opens in a new tab.
- You may need to make a copy of your work and put it in your scripts folder.
- Validate your html pages when finished.
- Upload your work to your server space.
- Mark the assignment as done when you have completed the above.