Create a Website
CSS Tutorial
FREE Domain!
Any web hosting you subscribe with DotEasy will get you a FREE domain name registration.
PLUS you get:
  • FREE Website Builder
  • FREE Blog
  • FREE Forum
  • FREE Photo Album
  • FREE Email Accounts
Get your FREE domain name today!
Home > JavaScript Tutorial
SSD Web Hosting with FREE Domain

Now it's time to get into some really fun stuff. Yes, Varaibles and functions. Don't worry, it's not as bad as it sounds... JavaScript variables are "containers" for storing information. let's start with declaring varaibles.

Declaring (Creating) JavaScript Variables

<SCRIPT language="JavaScript">
<!--hide from old browsers

var name=value;


Here is what these commands mean:

Using JavaScript Variables

For example, you could prompt your website users for their first name. When they enter their first name you could store it in a variable called say, firstName. Now that you have the user's first name assigned to a variable, you could do all sorts of things with it like display a personalised welcome message back to the user for example. By using a variable to store the user's first name, you can write one piece of code for all your users.

The Code

<script language="javascript" type="text/javascript" >
<!-- hide me
var firstName = prompt("What's your first name?", "");
// end hide -->
<!-- hide me
// end hide -->

The above example opens a JavaScript prompt, prompting the user for their first name. It will then write the name to the page (in practice, you would output the name somewhere between the tags).

Enjoy this tutorial?

1. Link to this page(copy/paste into your own website or blog):
2. Add this page to your favorite social bookmarks sites:
3. Add this page as your favorites. (Press Ctrl+D)