Skip to content

Latest commit

 

History

History
51 lines (35 loc) · 1.46 KB

05-identifier.md

File metadata and controls

51 lines (35 loc) · 1.46 KB

Identifiers

Identifiers

In JavaScript, an identifier is a name given to a variable, function, or other elements in a program. Identifiers are used to reference the elements they represent and are used throughout the program to access and manipulate data.

An identifier must start with a letter, underscore(_), or dollar sign($) and can be followed by any number of letters, digits, underscores, or dollar signs.

Rules for creating identifiers

JavaScript has a set of rules for naming variables and other elements known as naming conventions. Some of the common naming conventions are:

  • Variables and function should start with lowercase letters
  • Constants should be in uppercase
  • Avoid using reserved words as identifier names
  • Use camelCase for variable and function names
  • Use snake_case for constants

For example, the following code defines a variable called myVariable:

  • for example:
let myVariable = 10; //myVariable is an identifer
sum is an identifier here
function sum(a, b) {
console.log(a + b);
}

In this example, myVariable is the identifier for the variable.

JavaScript's Identifiers are a key aspect of the language, and are used extensively in web development to create dynamic and interactive web pages and for building web and mobile apps.

  • Invalid Identifier examples
let 12x = 10;
let &value = 10;
  • Valid Identifier examples
let x12 = 10;
let _value = 20;
let $_value = 100;