WebArtz - The Web Design Forum
Welcome to WebArtz, Guest!

WebArtz is a nice place for discussions related to web designing and coding. We help our members to code their own website templates with HTML and CSS. We give them advice on various issues.

To know more about WebArtz Forum, visit the About Us page.

At the moment, you are viewing the forum as a guest. As a guest you can't make post and participate in discussions. You need to register and become a member of the forum. Click the register link below and become a part of this forum.

Thank You


You are not connected. Please login or register

View previous topic View next topic Go down  Message [Page 1 of 1]

1Accespted Variables on Tue Feb 22, 2011 4:26 pm

Unknown Data


Registered Member
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.
Code:
var fruit = banana

Note: JavaScript uses loose typechecking, which means that you can define your variable without giving it a type (it's a whole other thing, don't think about that now).

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.

http://www.sjovfakta.dk

2Accespted Re: Variables on Fri Feb 25, 2011 6:01 pm

Jophy


Registered Member
Registered Member
Another good tutorial UD Very Happy

http://www.socialtechforum.com/

3Accespted Re: Variables on Fri Mar 04, 2011 10:41 am

WHITESABBATH


Registered Member
Registered Member
thank you sir. Wink

4Accespted Re: Variables on Mon Mar 07, 2011 12:22 am

Unknown Data


Registered Member
Registered Member
Thanks and glad to help Smile

http://www.sjovfakta.dk

5Accespted Re: Variables on Tue Nov 15, 2011 7:30 pm

Guest


Guest
Simple, nice and clean tutorial. Wink

View previous topic View next topic Back to top  Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum