Helping ordinary people create extraordinary websites!
HOME TUTORIALS SCRIPTS WEB HOSTING BLOG FORUM
Get Our Newsletter
Email:

JavaScript Tutorial Part I- Some Basics

By Will Bontrager
2004-02-09


How to make your program remember things

You can specify stuff that the JavaScript program must remember. And you can access that remembered stuff later on.

In order to store stuff in memory and access it later, that memory spot must have a name. The memory spot, itself, is called a "variable" because the contents of the memory spot can change.

To declare that a variable exists and give it a name, you type something like

var blahblah;

which creates a variable called "blahblah" where you can store stuff.

To store something into that memory spot, you type something like

blahblah = 5;

and the number "5" is stored in (assigned to) that memory spot.

You can also do all the above in one line, if you want, by typing

var blahblah = 5;

However, once a variable name has been declared, don't declare it again. If, later on in the program, you want to change the contents of the variable "blahblah", do it as a simple assignment statement, like

blahblah = 4;

To access what you have stored in a variable (the value you assigned to it), you either have to print it (have it show up on your web page) or assign it to another variable. To print it to your web page, you type

document.write(blahblah);

and, when interpreted and executed, that program line will print the value of "blahblah" on your web page.

Tutorial Pages:
» JavaScript Tutorial Part I- Some Basics
» Orientation
» How the browser knows it is JavaScript
» This is how JavaScript works
» Some programming basics
» How to make your program remember things
» Here it is, all put together
» Using strings of characters
» To come


Copyright 2004 Bontrager Connection, LLC


 | Bookmark
Related Tutorials:
» JavaScript Debugging Techniques with Firebug
» Striped Tables Using JavaScript
» Opening PDFs in a New Window with JavaScript
» Essential Javascript -- A Javascript Tutorial
» Submit Forms Conditionally using JavaScript
» How to Setup a Randomising Function

Ask A Question
characters left.