Variables

Let’s learn about variables in JavaScript.

What is a variable?

In general, a variable refers to anything that can vary. In JavaScript, a variable stores the data value that can be changed later on. We can use the reserved keyword var to declare a variable in JavaScript.

There are two types of variables:

  • With static variables, each variable and expression type is already known at compile time. Once a variable is declared to be of a certain data type, it cannot hold the values of other data types.
  • With dynamic variables, each variable can receive different data types over time.

In JavaScript, we use the second type. The following example will help us better understand what a dynamic variable is:

Get hands-on with 1400+ tech skills courses.