Skip to main content
Crowdfunding
Python + AI for Geeks
Practice

Identifiers and Literals

Identifiers and Literals are important concepts in programming languages, used to name variables, constants, functions, and to represent fixed values in the code.


Identifier

  • Definition: An identifier is a name used to identify variables, functions, objects, etc.
  • Example: In let appleCount = 5;, appleCount is an identifier.
  • Rules:
    • Identifiers can start with a letter, a dollar sign ($), or an underscore (_).
    • Subsequent characters can also be digits.
    • Reserved words cannot be used as identifiers. (e.g., let, if, etc.)

Literal

  • Definition: A literal is a fixed value that appears directly in the source code. It is used exactly as it is when assigned to a variable or used in an operation.
  • Example: In let appleCount = 5;, 5 is a numeric literal.
  • Types:
    • Numeric literal: e.g., 123, 3.14
    • String literal: e.g., "hello", 'world'
    • Boolean literal: e.g., true, false
    • Object literal: e.g., {name: "John", age: 30}
    • Array literal: e.g., [1, 2, 3]
    • Regular expression literal: e.g., /ab+c/

In short, an identifier is a name used to reference or call data or functions, while a literal is a fixed value directly used in the code.

Want to learn more?

Join CodeFriends Plus membership or enroll in a course to start your journey.