Welcome to JavaScript Finder
Javascript Variables
A variable's purpose is to store information to be used later. A variable is a name that represents some data that you set. The name stores the data so it can be used later in the program script. A variable's value can change during the script. You can call a variable by name to see its value or to change its value. JavaScript variables can hold data of any valid type. The variable can be a string, or a number. What ever you save in the variable is the data type it will be. JavaScript allows you to easily convert one type to another.
JavaScript : Example
price = 28000;
carprice ="The car costs " + price + " dollars."
document.write(carprice);
If you use a variable like this inside of a function, this makes it globally available to the rest of the script.
JavaScript : Example
function setUserName()
{
UserName = "Bobby Jackson";
}
Using the keyword var will make a variable local. Changing the code from above to add var in front of the UserName.
JavaScript : Example
function setUserName()
{
var UserName = "Bobby Jackson";
}