Home / Advanced JavaScript Tutorials / Variable and expression shortcuts

 

 

CodingForums
Having trouble with scripting? Visit our help forum to get the answers you need.

Jump to...
-Free JavaScripts
-JS tutorials
-JS Reference
-DHTML/CSS

-Free applets
-Web Tutorials
-Link to Us!

- CSS Drive
- PHP Resources
- Hotels & Vacations
- Bad credit cards
- JavaScript Menus


Red_CurlyC035.gif (995 bytes) Declaring many variables at once

Probably the most frequently done thing in programming is declaring variables. Whatever you do, however you do it, you can't live without these "containers". Most of us JavaScripters are probably used to declaring variables by using the "var" keyword in front of each variable we wish to declare, like this:

var Sam
var Joe
var Bob
var Mary

There is actually a quicker way when it comes to declaring multiple variables, and it looks like this:

var Sam, Joe, Bob, Mary

Simply use "var" once, followed by the names of the variables, each separated by a semicolon. You can also choose to initialize some/all of the variables upon declaration this way:

var Sam="10yr", Joe="30yr", Bob="15yr", Mary="21yr"

-Tutorial introduction
-Declaring many variables at once
-Assignment operator shortcuts
-The "with" statement
-The "?" conditional expression statement

Assignment operator shortcuts


http://javascriptkit.com
Copyright © 1997-2005 JavaScript Kit. NO PART may be reproduced without author's permission.