Results 1 to 20 of 70
Thread: JavaScript Variables
-
04-24-2011, 07:05 PM #1
MTV Rookie
This user has no status.I am:----
- Join Date
- Apr 2011
- Posts
- 89
- MTV$
- 398
JavaScript Variables
Variables are "containers" for storing information.
Do You Remember Algebra From School?
Do you remember algebra from school? x=5, y=6, z=x+y
Do you remember that a letter (like x) could be used to hold a value (like 5), and that you could use the information above to calculate the value of z to be 11?
These letters are called variables, and variables can be used to hold values (x=5) or expressions (z=x+y).
JavaScript Variables
As with algebra, JavaScript variables are used to hold values or expressions.
A variable can have a short name, like x, or a more descriptive name, like carname.
Rules for JavaScript variable names:
Variable names are case sensitive (y and Y are two different variables)
Variable names must begin with a letter or the underscore character
Note: Because JavaScript is case-sensitive, variable names are case-sensitive.
Example
A variable's value can change during the execution of a script. You can refer to a variable by its name to display or change its value.
This example will show you how
Declaring (Creating) JavaScript Variables
Creating variables in JavaScript is most often referred to as "declaring" variables.
You declare JavaScript variables with the var keyword:
var x;
var carname;
After the declaration shown above, the variables are empty (they have no values yet).
However, you can also assign values to the variables when you declare them:
var x=5;
var carname="Volvo";
After the execution of the statements above, the variable x will hold the value 5, and carname will hold the value Volvo.
Note: When you assign a text value to a variable, use quotes around the value.
Note: If you redeclare a JavaScript variable, it will not lose its value.
Local JavaScript Variables
A variable declared within a JavaScript function becomes LOCAL and can only be accessed within that function. (the variable has local scope).
You can have local variables with the same name in different functions, because local variables are only recognized by the function in which they are declared.
Local variables are destroyed when you exit the function.
You will learn more about functions in a later chapter of this tutorial.
Global JavaScript Variables
Variables declared outside a function becomes GLOBAL, and all scripts and functions on the web page can access it.
Global variables are destroyed when you close the page.
If you declare a variable, without using "var", the variable always becomes GLOBAL.
Assigning Values to Undeclared JavaScript Variables
If you assign values to variables that have not yet been declared, the variables will automatically be declared as global variables.
These statements:
x=5;
carname="Volvo";
will declare the variables x and carname as global variables (if they don't already exist).
JavaScript Arithmetic
As with algebra, you can do arithmetic operations with JavaScript variables:
y=x-5;
z=y+5;
-
04-24-2011 07:05 PM # ADSAdvertise here Circuit advertisement
- Join Date
- My Birthday
- Posts
- Million and counting
-
09-13-2012, 11:49 PM #2
Banned
This user has no status.I am:----
- Join Date
- Sep 2012
- Posts
- 1,129
- MTV$
- 3,336
Re: JavaScript Variables
thank you keep it up!!! i got to know many thin from the post. this post is such a wonderful that everybody can learn many things from this. thank you keep it up!!!
-
10-03-2012, 03:38 PM #3
Banned
is is banned for copy pastingI am:----
- Join Date
- Oct 2012
- Posts
- 340
- MTV$
- 1,000
Re: JavaScript Variables
JavaScript variables are "containers" for storing information:
eg
var x=5;
var y=6;
var z=x+y;
As with algebra, JavaScript variables can be used to hold values (x=5) or expressions (z=x+y).
Variable can have short names (like x and y) or more descriptive names (age, sum, totalvolume).
Variable names must begin with a letter
Variable names can also begin with $ and _ (but we will not use it)
Variable names are case sensitive (y and Y are different variables)
-
05-09-2013, 04:52 AM #4
Banned
This user has no status.I am:----
- Join Date
- May 2013
- Posts
- 674
- MTV$
- 2,000
Re: JavaScript Variables
there are many things such as JavaScript variable scope and so many other things. they are considered to be one of the JavaScript variable scope that is one of the global variables and another one of the local variables. they are used to provide one of the names must begin with a letter.
-
05-10-2013, 09:42 AM #5
Banned
This user has no status.I am:----
- Join Date
- May 2013
- Posts
- 674
- MTV$
- 2,000
Re: JavaScript Variables
they are used to be one the local variables is considered to be one of the visible only within a function and so many other things. they are used to provide the function parameters and so many other things. they are used to be one of the local to that function and so many other things.
-
05-10-2013, 10:38 AM #6
Banned
This user has no status.I am:----
- Join Date
- May 2013
- Posts
- 674
- MTV$
- 2,000
Re: JavaScript Variables
they are used to provide that the variable names is considered to be one of the case sensitive and so many other things. they are used to know about two different variables is to be considered and so many other things. there are many things such as variable names must begin with a letter and so many other things.
-
05-10-2013, 11:01 AM #7
Banned
This user has no status.I am:----
- Join Date
- May 2013
- Posts
- 674
- MTV$
- 2,000
Re: JavaScript Variables
they are used to be one of the variable is considered to be one of the value and so many other things. they are used to provide that the variable is considered to be one of the change during the execution of a script and so many other things. they are used to know about that the variable refer by its name to display.
-
05-10-2013, 01:07 PM #8
Banned
This user has no status.I am:----
- Join Date
- May 2013
- Posts
- 674
- MTV$
- 2,000
Re: JavaScript Variables
they are used to provide one of the variables and equations in algebra and so many other things. they are used to know about variables like a, b, c store numbers and so many other things. they are considered to be one of the JavaScript, other programming language and so many other things.
-
05-10-2013, 01:10 PM #9
Banned
This user has no status.I am:----
- Join Date
- May 2013
- Posts
- 674
- MTV$
- 2,000
Re: JavaScript Variables
they are used to be one of the information such as names to store them and so many other things. they are used to know about the scripting language and so many other things. they are used to be one of the memory such as to stores in computer's memory and so many other things.
-
05-10-2013, 01:12 PM #10
Banned
This user has no status.I am:----
- Join Date
- May 2013
- Posts
- 674
- MTV$
- 2,000
Re: JavaScript Variables
they are used to be one of the scripting language and so many other things. they are used to provide about the javascript such as strings, numbers, variables, boolean, operators, function, loop, void keyword, dialog boxes, page printing and so many other things. they are used to be five rules for naming variables in JavaScript.
-
05-10-2013, 01:13 PM #11
Banned
This user has no status.I am:----
- Join Date
- May 2013
- Posts
- 674
- MTV$
- 2,000
Re: JavaScript Variables
they are used to be one of the first character is considered to be one of the letter (a-z, A-Z) or an underscore (_) and so many other things. they are used to provide about the boolean, operators, function, loop, void keyword, dialog boxes, page printing and so many other things.
-
05-10-2013, 01:16 PM #12
Banned
This user has no status.I am:----
- Join Date
- May 2013
- Posts
- 674
- MTV$
- 2,000
Re: JavaScript Variables
there are many things such as the rest of the name is considered to be one of the made up of letters that is letters a-z , numbers 0-9 or underscore _ and so many other things. they are used to be one of the of JavaScript variable naming to understand in a very easy thing and so many other things.
-
05-10-2013, 01:18 PM #13
Banned
This user has no status.I am:----
- Join Date
- May 2013
- Posts
- 674
- MTV$
- 2,000
Re: JavaScript Variables
they are all know that the variable name cannot contains space character and so many other things. they are used to allow that one of the variable is considered to be a short name such as x and so many other things. they are used to provide more descriptive name such as carname and so many other things.
-
05-10-2013, 01:21 PM #14
Banned
This user has no status.I am:----
- Join Date
- May 2013
- Posts
- 674
- MTV$
- 2,000
Re: JavaScript Variables
they are used to be one of the case sensitive and so many other things. they are used to provide that the JavaScript variables is considered to be one of the case sensitive and so many other things. they are used to know about the name is different from another one of the names and so many other things.
-
05-10-2013, 01:24 PM #15
Banned
This user has no status.I am:----
- Join Date
- May 2013
- Posts
- 674
- MTV$
- 2,000
Re: JavaScript Variables
they are used to provide one of the "reserve words" such as alert and so many other things. they are used to be one of the variable name as var and so many other things. there are many things such as reserve words in one of the laptop computer and so many other things.
-
05-10-2013, 01:26 PM #16
Banned
This user has no status.I am:----
- Join Date
- May 2013
- Posts
- 674
- MTV$
- 2,000
Re: JavaScript Variables
they are used to be available that the first character must be a letter or an underscore (_) and many other things. they are used to uderstand one of the javaScript variable name and so many other things. they are used to be one of the scripting language and so many other things.
-
05-10-2013, 01:29 PM #17
Banned
This user has no status.I am:----
- Join Date
- May 2013
- Posts
- 674
- MTV$
- 2,000
Re: JavaScript Variables
they are used to provide that the valid variable name is considered to be one of the employee_77 and so many other things. they are used to be one of the scripting language about the javascript and so many other things. they are used to allow that javaScript variables are case sensitive.
-
05-10-2013, 01:33 PM #18
Banned
This user has no status.I am:----
- Join Date
- May 2013
- Posts
- 674
- MTV$
- 2,000
Re: JavaScript Variables
they are used to allow one of the valid variable name such as variable_name, x and so many other things. they are used to know about that JavaScript variables is considered to be one of the using hold values or expressions and so many other things. they are used to know about the scripting language.
-
05-10-2013, 01:35 PM #19
Banned
This user has no status.I am:----
- Join Date
- May 2013
- Posts
- 674
- MTV$
- 2,000
Re: JavaScript Variables
there are many things such as declaring variables, valid variable name, invalid variable name, naming variables and so many other things. they are used to provide to understand one of the variable and so many other things. they are used to allow one of the var emp_name is considered to be the variable.
-
05-10-2013, 01:37 PM #20
Banned
This user has no status.I am:----
- Join Date
- May 2013
- Posts
- 674
- MTV$
- 2,000
Re: JavaScript Variables
they are used to provide that the keyword var is considered to be followed by name of the variable and so many other things. they are used to provide one of the declaration and so many other things. they are used to know about to declare a new variable and so many other things.
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)

































Reply With Quote



Bookmarks