spacer
Web Development Learn JavaScript
 Developer Newsletter

Learn JavaScript
JavaScript Tutorial
Introduction to JavaScript
JavaScript Getting Started
JavaScript Syntax
JavaScript Variables
JavaScript Functions
JavaScript If Statement
JavaScript While Loop
JavaScript For Loop
JavaScript Comments
JavaScript Syntax Reference
Advanced JavaScript
JavaScript Switch Statement
JavaScript Arrays
JavaScript Objects
JavaScript getElementById
JavaScript Popup Windows
JavaScript Redirect
JavaScript Cookies
JavaScript Events
JavaScript No Right Click
JavaScript Strings
Detecting Browsers

Tutorials
AJAX
ASP
CGI & Perl
CSS
Flash
HTML
Illustrator
Java
JavaScript
Linux
MySQL
PHP
Photoshop
Python
Wireless
XML
Miscellaneous


Scripts Directory
AJAX Scripts
ASP Scripts
ASP.NET Scripts
CGI & Perl Scripts
Flash Scripts
Java Scripts
JavaScript Scripts
PHP Scripts
Python Scripts
Remotely Hosted Scripts
Tools & Utilities Scripts
XML Scripts

JavaScript Variables

Data types

In the previous section, JavaScript Syntax, we looked at a variable set to a string. We call a string a data type, as it is a type of information that a variable can hold. But variables can hold so much more. Here are some examples of variables being assigned different datatypes:

'Sometext' A string value
105 An integer value
true A boolean value

Remember, only strings, or snippets of text, need to be quoted. You can also use numbers with decimals; these are called float values. You can assign any variable to any of these values, like this:

somevariable = 'Some text';
someothervariable = 105;
athirdvariable = 12.10;
ourfinalvariable = true;

Creating variables

Variable names must begin with a letter or an underscore, and can have letters (both capital and lowercase), numbers and underscores. Variable names are case sensitive: myvar is not the same as myVar. When you assign a variable a value, the variable is automatically created.

You should also use the var keyword when first creating a variable, like so:

var myName = "Josh";
var has_happened = true;

With the var keyword, you can also create multiple variables at the same time:

var myName = "Josh", has_happened = true;

Now, let's take a look at JavaScript functions.

« JavaScript Syntax JavaScript Functions »

More JavaScript Tutorials:
» New Browser Window Checkbox
» Validating Form Input - II
» Javascript setTimeout Problem
» Writing Classes in Javascript
» Changing Form Action URLs On-The-Fly
» Validating Form Input I


About the NetVisits, Inc Network | Write For Us | Advertise
Copyright ©2007 NetVisits, Inc Network. All Rights Reserved. Privacy Policy.
Visit other NetVisits, Inc. sites: