You are currently viewing What is Identifier in Javascript With Example | Advanced Guide

What is Identifier in Javascript With Example | Advanced Guide

What is Identifier in Javascript

This article is about what is identifier in javascript and the naming convention you have to follow in identifiers.

What is an identifier?

It is a sequence of character, which help us to identify a specific part of a program. Identifiers are names given by the programmer to program components and It is user-defined names.

name of variable
name of constant  etc.,

Follow the Naming convention

It means the rules for writing identifier names. Here I have listed seven naming conventions you have to follow these rules while writing an identifier name.

  1. Identifiers should be meaningful. You do not write x,y,p, s like that. You should use some proper meaningful names like ‘price’, which indicates some product price, and ‘score’, which indicates some player score. Simply do not use characters for naming variables or constants or functions they are not more meaningful.
  2. Keywords should never be used as identifiers, like ‘continue’ it’s an invalid identifier name because ‘continue’ is a keyword. You should not use keywords as identifiers.
  3. The first character can be an alphabet, underscore, or dollar character. The first character should not be a number like “9thplayer”.
  4. After the first character, the next characters can be alphabets or underscores, or digits.
  5. No special characters are allowed except an underscore or dollar sign. While naming an identifier, you can use only dollar and underscore and no other special characters are allowed like you cannot use %, *, @, etc.
  6. More than one successive underscore or dollars should not be used like “$$balance” in the below example.
  7. Identifiers are case-sensitive. You have written ‘Num’ and ‘num’, they have the same name but still, the javascript treats both of them as a separate identifiers. Because here the first character is in uppercase. It treats uppercase and lowercase letters completely differently.
READ ALSO  Top 10 Tips To Make your Code Cleaner in Javascript

Valid identifier names:

Num , num, _flag, player9, $price, SCREEN_WIDTH, setWidth, Student etc.
Invalid identifier names:

s, p, 9thplayer, _ _flag, $$balance, etc.


I hope you guys have clearly understood what is identifiers and what are the naming conventions you have to follow while forming an identifier name.

Leave a Reply