Home arrow JavaScript arrow Page 6 - 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 - White Spaces and Case Sensitivity
(Page 6 of 6 )

White spaces are the spaces, tabs and line breaks that you use to improve your code readability. We could write the script in the example as follows:

var firstValue = 10;var secondValue = 23;var result = firstValue + secondValue;
document.write("The total of adding firstValue and secondValue = ");document.write(result);

We have written three statements in first line and two statements in the second line. If you saved the code like this it will be executed in the same way. So white spaces are used to make your code look better and organized. You can't use white spaces inside an identifier, so you can't write the identifiers in our example as follows:

<script language="JavaScript" type="text/javascript">
var first Value = 10;
var second Value = 23;
var result = first Value + second Value;
document.write("The total of adding firstValue and secondValue = ");
document.write(result);
</script>

Replace the <script> block of the Web page with the above one and save the page. When you load it into IE and Firefox you will get the following error messages, respectively:

These error messages tell us that the interpreter expects a semicolon after the first, because it considers it an identifier for a variable.

Javascript keywords and identifiers are case-sensitive, which means that the identifier firstValue is not the same as FIRSTVALUE or FirstValue. They are different in their capitalization, and to the Javascript interpreter they are not the same, so they can be used as identifiers for different variables. Because of that, if you defined your variable as firstValue, and somewhere in the script you use FirstValue, you will get an error message, as with the following code:

<!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 firstValue = 10;
var secondValue = 23;
var result = FirstValue + secondValue;
document.write("The total of adding firstValue and secondValue = ");
document.write(result);
</script>
</head>
<body>

</body>
</html>

When you save this file and load it into your browser, you will get the following Error Messages in IE 6 and Firefox 1.3:

You get the Error: FirstValue is not defined, because Javascript is case-sensitive. We have declared the variable as firstValue, which is different from FirstValue, as we have said.

Actually, there is a problem that you will encounter while you are programming, which is the casing style you use for your identifiers. There are two casing conventions used among programmers, Pascal casing and camel casing. Pascal casing states that all the words in your identifier begin with a capital letter, and there's no character that separates the words. For example, the identifiers FirstValue, SecondValue, and Result all display valid Pascal casing.

Camel casing states that the first word of your Identifier begins with a small letter, the following words in the Identifier begin with a capital letter, and there are no characters that separate the words. We will use the camel casing for variable identifiers; we will talk about variables and data types in detail in the next article.

So the example contains comments, keywords, identifiers and statements (plus other things which we don't need to know now). It simply declares two memory locations, stores some values there, then add them, puts the result in a third variable, and writes it to the Web page. I will take you step-by-step through the various examples in thsi article series, so you won't find any difficulties.


DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

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