JavaScript identifiers

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

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.

Nathan Pakovskie is an esteemed senior developer and educator in the tech community, best known for his contributions to Geekpedia.com. With a passion for coding and a knack for simplifying complex tech concepts, Nathan has authored several popular tutorials on C# programming, ranging from basic operations to advanced coding techniques. His articles, often characterized by clarity and precision, serve as invaluable resources for both novice and experienced programmers. Beyond his technical expertise, Nathan is an advocate for continuous learning and enjoys exploring emerging technologies in AI and software development. When he’s not coding or writing, Nathan engages in mentoring upcoming developers, emphasizing the importance of both technical skills and creative problem-solving in the ever-evolving world of technology. Specialties: C# Programming, Technical Writing, Software Development, AI Technologies, Educational Outreach

Leave a Reply

Your email address will not be published. Required fields are marked *

Back To Top