TabletWise.com
 

Global Scope - Demonstration

1 minutes
Share the link to this page
Copied
  Completed
You need to purchase the class to view this lesson.
One-time Purchase
$99.99
List Price:  $139.99
You save:  $40
د.إ367.25
List Price:  د.إ514.17
You save:  د.إ146.91
A$137.13
List Price:  A$192
You save:  A$54.86
৳8,478.82
List Price:  ৳11,870.69
You save:  ৳3,391.87
CA$132.04
List Price:  CA$184.86
You save:  CA$52.82
CHF 91.14
List Price:  CHF 127.60
You save:  CHF 36.46
kr628.27
List Price:  kr879.61
You save:  kr251.33
€84.45
List Price:  €118.23
You save:  €33.78
£77.41
List Price:  £108.38
You save:  £30.96
HK$774.92
List Price:  HK$1,084.92
You save:  HK$310
₹7,360.27
List Price:  ₹10,304.68
You save:  ₹2,944.40
RM411.40
List Price:  RM575.98
You save:  RM164.58
₦38,296.17
List Price:  ₦53,616.17
You save:  ₦15,320
kr909.39
List Price:  kr1,273.19
You save:  kr363.79
NZ$147.85
List Price:  NZ$207
You save:  NZ$59.14
₱4,848.01
List Price:  ₱6,787.41
You save:  ₱1,939.40
₨16,648.33
List Price:  ₨23,308.33
You save:  ₨6,660
S$135.99
List Price:  S$190.40
You save:  S$54.40
฿3,107.53
List Price:  ฿4,350.67
You save:  ฿1,243.13
₺755.67
List Price:  ₺1,057.97
You save:  ₺302.30
B$539.07
List Price:  B$754.72
You save:  B$215.65
R1,633.40
List Price:  R2,286.82
You save:  R653.42
Already have an account? Log In

Transcript

Opened the examples folder and then open the global scope sub folder. Now let's look at the exe example global scope one. Here I have a global variable called speed, I know that's global because it's not in a function is defined outside of a function. So I declare the the variable speed, which is equal to 25. And then I have a console log statement outputting, that variable, and we should get 25 in the console. So if I click show examples, and then global scope, example one, we can see we get global speed 25 not a big surprise.

So let's look at global scope number two. So once again, I have the global variable speed, which is equal 25. But then I have this function inside of the function. I also output in the console speed from foo, which is the global speed variable defined on line three. And then on line nine, I have the console log statement to output, the value the global variable and online 10 execute foo, which also outputs that global variable. So let's take Look at show examples global scope two.

And I see the two messages speed from global scope 25 speed one through 25. Pretty simple stuff. But the point here is that a global variable is one is defined in the global scope. And we know we're in in global scope if we're not in a function, because variable speed is not defined in a function, which means it's global, even though we access it in a function on line six. This speed variable right here is still referencing the global speed. And then we're outputting it here.

So just remember that a global variable is one that is defined outside of a function

Sign Up

Share

Share with friends, get 20% off
Invite your friends to TabletWise learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.