Geekpedia Tutorials Home

Building a C# Chat Client and Server

Building a C# Chat Client and ServerA step by step tutorial teaching you how to create your own chat client and chat server easily in C#, for local networks or the Internet.

in C# Programming Tutorials

Getting Hard Drive Information

Getting Hard Drive InformationA C# tutorial showing you how to make use of WMI to extract information on disk drives, such as model, capacity, sectors and serial number.

in C# Programming Tutorials

UPS Shipping Calculator

UPS Shipping CalculatorThis tutorial will teach you how to calculate the shipping cost based on the weight, height, length and depth of the box, the distance and the UPS service type.

in PHP Programming Tutorials

Create Your Own Rich Text Editor

Create Your Own Rich Text EditorCreating a Rich Text Editor using JavaScript is easier to do than you might think, thanks to the support of modern browsers; this tutorial will walk you through it.

in JavaScript Programming Tutorials
Search
Tutorials
Programming Tutorials
IT Jobs
From CareerBuilder

JavaScript identifiers

You will learn the meaning of identifiers and basic rules. It's good to know before you start to learn variables.

On Monday, March 8th 2004 at 10:43 AM
By Andrew Pociu (View Profile)
*****   (Rated 4.4 with 14 votes)
Contextual Ads
More JavaScript Resources
Advertisement

Yet, this is another fragment of the book I started to write some time ago, named 'JavaScript class'. This section covers some basic information about JavaScript and also applies to other programming languages... a bit.

A token is something representing something else. Pretty confusing . Tokens represent words that JavaScript can understand. When the JS interpreter works, he identifies tokens and processes them. Still confused ? All the functions, variables… all the commands a script contains, are tokens. What I said isn’t entirely correct, but I’m putting it this way for you to understand. In fact, a token is a category that holds other subcategories which holds variables, functions etc. Identifiers are one of these token categories.

What are identifiers


An identifier is a symbol that represents, names a piece of data. An identifier can represent a function or a variable, for example. There are some rules regarding the identifiers.

Identifiers rules


We settled that identifiers are names that represent pieces of data. You name your own identifiers, in fact that’s the most important thing regarding identifiers. But you must respect some rules when you name your own variables:
Your identifiers must start with a letter, or with the underscore sign ‘_’. You cannot start an identifier with a digit, or with some other sign like $, %, @, etc. But after the first character in your identifier, you can use digits to build your identifier name.
You cannot use space in your identifiers. If you must specify two or more words in an identifier, you can use the underscore sign or capitalize the second word, like this:


total_price
TotalPrice



It’s easier to read than:


totalprice



The following examples of identifiers are correct:


MyVar
Var1
Total_Price
_ConstPrice
X



And the following are incorrect:


1stVar
total price
$Price


Therefore be very careful when you choose your identifier name, if you break the rules, the browser will most probably throw a hard to debug error. There is one more thing you must be aware of – the reserved identifiers.

Reserved identifiers


JavaScript has some predestinated identifiers, and of course, you can’t use the name of those identifiers to specify your own, because it will be confusing for you and your browser. And identifiers represent variables, functions… so I think it’s clear to you that you can’t use these names for them either.
This is the list of reserved words:


abstract
boolean
break
byte
case
catch
char
class
const
continue
debugger
default
delete
do
double
else
enum
export
extends
false
final
finally
float
for
function
goto
if
implements
import
in
instanceof
int
interface
long
native
new
null
package
private
protected
public
return
short
static
super
switch
synchronized
this
throw
throws
transient
true
try
typeof
var
void
volatile
while
with


Case sensitivity


All JavaScript identifiers are case sensitive. That means that SomeWord, someword, Someword, someWord and SoMeWoRd are different identifiers. You can make use for case sensitivity, and specify more variables, for example, that sound the same, but are written different. But you’ll find that confusing for you.
Digg Digg It!     Del.icio.us Del.icio.us     Reddit Reddit     StumbleUpon StumbleIt     Newsvine Newsvine     Furl Furl     BlinkList BlinkList

Rate Rate this tutorial
Comment Current Comments
by Rob on Tuesday, October 23rd 2007 at 10:28 PM

The naming scheme is incorrect. You do not have to have two words to assign an identifier. But it is better form to do so. Also, the first letter does not need to be capitalized.

myVar is correct
thisMessage is also correct
ThisMessage is equally correct

by Andrei on Tuesday, October 23rd 2007 at 11:00 PM

The tutorial doesn't say you need two words to assign an identifier.

by darko on Sunday, June 15th 2008 at 07:46 AM

The $ is allowed as the first character.


Comment Comment on this tutorial
Name: Email:
Message:
Comment Related Tutorials
There are no related tutorials.

Comment Related Source Code
There is no related source code.

Jobs JavaScript Job Search
My skills include:
Enter a City:

Select a State:


Advanced Search >>
Sponsors
Discover Geekpedia

Other Resources