The Power of Javascript: Basic Concepts - Identifiers
(Page 5 of 6 )
When you declare a variable in the memory, how will you refer to it? You use an identifier to refer to your variable. An identifier is simply a name that is used to reference a variable (or as we are going to see, other programming constructions like functions), so in our example we have three Identifiers that refer to our three variables:
var firstValue = 10;
var secondValue = 23;
var result = firstValue + secondValue;
The identifier firstValue is the name of the variable that stores the value 10 in the memory. The identifier secondValue is the name of the variable that stores the value 23 in the memory. The result is the name of the variable that stores the value 10 (of the variable firstValue) plus the value 23 (of the variable secondValue). So we use identifiers to name our programming constructions.
Note that you declare a variable using the keyword var followed by the variable identifier. We will talk about variables and data types in the next article.
You can't use var as an identifier because it's a keyword that has been reserved by the Javascript language, so it will produce errors and problems when used. Let's try to use the keyword else as an identifier for a variable.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Hello World</title>
<script language="JavaScript" type="text/javascript">
var else = 134;
document.write(else);
</script>
</head>
<body>
</body>
</html>
We have used the var keyword to declare a variable, followed by the variable identifier, then its value (134). Save the file and load it in your IE Browser. You will get the following error message:

Error: Expected identifier means that the Javascript interpreter was not able to find the variable's identifier. We used the keyword var so the interpreter would understand that we need to declare a variable. Next we used else as the identifier, but the interpreter knows that else is a reserved keyword so it tells you that it expected an identifier.
If you run this code in Firefox you will get a better error message. Open the Web page with Firefox. Go to Tools, then choose Javascript Console, and you will get the following error message to the console:

Next: White Spaces and Case Sensitivity >>
More JavaScript Articles
More By Michael Youssef