Dan Chui
Happy Bytes
javascript

JavaScript Fundamentals: Variables and Identifiers

JavaScript Fundamentals: Variables and Identifiers
0 views
2 min read
#javascript
Table Of Content

Let's do a quick breakdown of Variables and Identifiers, which are essential for writing JavaScript code.

JavaScript is a Dynamic Type language: variables have no types, and can change typing. Additionally, variables are checked during run-time (the execution stage).

Variables

Variables are basically containers for storing data, and can be declared in 4 ways:

  1. Automatically
  2. Using let
  3. Using const
  4. Using var

These variables carry rules that a JavaScript writer should remember:

  1. Always declare variables
  2. Always use const if the VALUE should not be changed
  3. Always use const if the TYPE should not be changed (for Arrays and Objects)
  4. Only use let if you cannot use const
  5. Only use var if you need to support older browsers

Identifiers

All JavaScript variables must be identified with unique names.

These unique names are called Identifiers.

Identifiers can be short names (like x and y) or more descriptive names (age, distance, totalWeight).

The general rules for constructing names for variables (unique identifiers) are:

  1. Names can contain letters, digits, underscores, and dollar signs.
  2. Names must begin with a letter.
  3. Names can also begin with $ and _
  4. Names are case sensitive (a and A are different variables).
  5. Reserved words (such as JavaScript keywords) cannot be used as names.