Home arrow JavaScript arrow Page 5 - The Power of Javascript: Basic Concepts
JAVASCRIPT

The Power of Javascript: Basic Concepts


The best way to learn any programming language is by practice. Javascript is not an exception to this rule, so we will introduce a lot of code in the articles of this series. In this article, you will be introduced to the very basic concepts of the Javascript language. We discuss comments, keywords, identifiers, statements and the semicolon, case sensitivity and white spaces. Note that our examples at this time are limited and we will focus more on the concepts, but after a few articles we are going to discuss many examples on each concept.

Author Info:
By: Michael Youssef
Rating: 4 stars4 stars4 stars4 stars4 stars / 30
July 05, 2005
TABLE OF CONTENTS:
  1. · The Power of Javascript: Basic Concepts
  2. · Javascript Comments
  3. · Javascript Statements
  4. · Keywords
  5. · Identifiers
  6. · White Spaces and Case Sensitivity

print this article
SEARCH DEVARTICLES

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:


blog comments powered by Disqus
JAVASCRIPT ARTICLES

- Project Nashorn to Make Java, JavaScript Wor...
- JavaScript Virus Attacks Tumblr Blogs
- Google Releases Stable Dart Version, JavaScr...
- Khan Academy Unveils New JavaScript Learning...
- Accessing Nitro? There`s an App for That
- JQuery 2.0 Leaving Older IE Versions Behind
- Fastest JavaScript Engine Might Surprise You
- Microsoft Adjusting Chakra for IE 10
- Brendan Eich: We Don`t Need Google Native Cl...
- An Overview of JavaScript Statements
- An Overview of JavaScript Operators
- Overview of JavaScript Variables
- More of the Top jQuery Social Plugins
- The Top jQuery Social Plugins
- More of the Top jQuery Slider Plugins

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials