Basics: Literals, identifiers and variables

Literals

We define as literal a value that is written in the source code, for example, a number, a string, a boolean, or also more advanced constructs we will see later during the course, like Object Literals or Array Literals:

5
'Test'
true

['a', 'b'] 
{color: 'red', shape: 'Rectangle'}

This is the simplest “unit” of JavaScript.

Identifiers

An identifier is a sequence of characters.

We’ll use identifiers to identify a variable, a function, or an object.

An identifier can start with a letter, the dollar sign $, or an underscore _, and it can contain digits.

Test
test
TEST
_test
Test1
$test

The dollar sign is commonly used to reference DOM elements.

Some names are reserved for JavaScript internal use, and we can’t use them as identifiers.

Variables

When we need to have a reference to a value, we assign it to a variable.

The variable can have a name, and the value is what’s stored in a variable, so we can later access that value through the variable name.

A variable is a value assigned to an identifier, so you can reference and use it later in the program.

This is because JavaScript is loosely typed, a concept you’ll frequently hear about.

We have 3 main ways to declare variables. The first is to use const:

const a = 0

The second way is to use let:

let a = 0

We also have var:

var a = 0

It’s important to note that identifiers are case sensitive.

Lessons in this unit:

0: Introduction
1: ▶︎ Literals, identifiers and variables
2: Comments
3: The difference between let, const and var
4: Types
5: Operators and expressions
6: Let's start with arithmetic operators
7: The assignment operator
8: Operators precedence
9: Strings
10: Numbers
11: Semicolons, white space and sensitivity
Want to learn more? Check out our courses