1 Variables Tue Feb 22, 2011 5:56 pm
Unknown Data
Registered Member
Variables Learn JavaScript - Part 3 |
Variables is a form of a container, were we can save a value. The value can either be a numeric character or a textstring. A variable is declared by the word var followed by a value. To define/declare a variable The variables declared within the function it's used in, stays local and only current for that function. Is the variable defined outside a function, will it recieve a global sphere aka. scope. That means that the function is current for the whole document. Below here, have I added an example of a variable named fruit, and the value of the fruit is banana.
Scope The variables scope is that area of the script, were the script itself can be used. It distinguishes between two types of variables, global and local. It's very confusing right? So let's take a look at what global and local variables is. Local variables A local variable is declared within the function you wish to use. The scope for this functions is henced by the function itself. If another function whereas the variable, can't the function getting readed or changed it's value. Global variables Global variables is declared inside the funtion of the top of the script. These functions can getting readed and changed by any function. Other rules for variables • No space between the variable names. • Do not make them longer than 32 signs. • They can only consist of letters and numbers. • The first sign should be a letter or underscore. • You can't use JavaScript reserved words. In the next lesson are we going to learn about the objects. |
Notice : This tutorial is copyrighted by WebArtz Forum. You may not publish it on anywhere without written permission from the administrators. |