GeezerVison is showing github.com — Basics Closure README.md · asifmn/JavaScript-Lessons@ce9a9c7
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboard +26-6Lines changed: 26 additions & 6 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | + |
1 | 2 |  |
2 | 3 |
|
3 | 4 | ## Closures |
@@ -7,12 +8,31 @@ enclosing scope). In other words, these functions 'remember' the environment in |
7 | 8 |
|
8 | 9 | # Course Documentation |
9 | 10 |
|
10 | | -(this for me to fill up with every element that you use in lessons. syntax explaination and links for more) |
| 11 | +## Scope and Variables |
| 12 | + |
| 13 | +Variables are the names of the places that some value is stored and the most typical syntax to create them is: |
11 | 14 |
|
12 | | -## Element to explain |
| 15 | + var variablesname = valueofvariable; |
| 16 | + |
| 17 | + |
| 18 | +and after the creation we are typically changing the value with this syntax: |
| 19 | + |
| 20 | + variablesname = newvalueforthevariable; |
| 21 | + |
| 22 | + |
| 23 | +And if it is not clear the easiest thing in the world is to access the variable just by writing the variable there where we will use its value: |
13 | 24 |
|
14 | | -(for example console.log) |
| 25 | + console.log(variablesname) |
| 26 | + |
| 27 | + |
| 28 | +Scope on the other hand is about variable's inheritance, (with other words how accessible can a variable be). Typically it has two levels: |
| 29 | + |
| 30 | + - **Global** External variable when every function can access it. |
| 31 | + - **Local** Internal variable when only the function that |
| 32 | + |
| 33 | + |
| 34 | +In our example we used things like this. to manipulate our variables in a special way. This is called a JavaScript closure. It makes it possible for a function to have "private" variables or use private variables in a special way. (see Objected Oriented Programming or Classes.) |
| 35 | + |
| 36 | +For more information please check the [W3schools Javascript closures' documentation page](http://www.w3schools.com/js/js_function_closures.asp). |
15 | 37 |
|
16 | | -***Links*** |
17 | | - - Wikipedia |
18 | | - - Anotherlink,com |
| 38 | +> Written with [StackEdit](https://stackedit.io/). |