Northcentral Technical College Introduction To Programming
10-152-310
Introduction to Programming with JavaScript NTC 10-152-310

Learning Plan 5 Global Scope Demo

# Global Scope Demo

#### File: /Learning Plan 5/globalScope.html

- Global Scope in action.

### Here's the code:

### Output:

### What Happened?

- Lines 12 and 13: These variables have `Global Scope`, they're available to every function in the file. Functions can read and write to them.
- Line 44: The start of the first called function, this one is being called from the HTML page.
- Lines 49 and 51: "What? We haven't see this before!" That's correct, we are going to start using a different way to add our output to the page. We will use a common technique that sits in between the `document.write()` function and full `DOM Manipulation` on the scale of good ways to dynamically change an HTML page. Don't worry, we'll go over this a lot. For now just realize that we can get access to the HTML elements on a page with JavaScript.
- Lines 54 and 55: This will set the values of the global variables.
- Line 59: Actually adds an `<li>` tag to the `<ul>` tag that is already on the page.
- Line 62: This is the function call to the other function in the file. The current function will be suspended and the program will continue running at the beginning of the called function.
- Lines 21 and 23: This function also gets access to the list element on the page.
- Lines 26 and 27: This code is changing the value of the global variables. It overwrites that the first function set in them.
- Line 31: Here we are adding another `<li>` element to the `<ul>` tag. Notice the `+=`, we need this to not overwrite the other elements that have been added to the `<ul>` tag.
- Line 62: Here we are, back at the spot where we suspended the first function. The function will start running again from the next statement after the function call.
- Line 66: One final `<li>` tag will be add to the `<ul>` tag to see what is currently in the global variables.