Variables

Learn about and practice with variables in JavaScript.

Variables are used in programming languages to refer to a value stored in memory. They give us a convenient way to refer to different values in a program. They can be thought of as labels that point to different values. Variables are a useful way of dealing with long expressions because they save us from typing these expressions over and over again.

Declaring and assigning variables

In most programming languages, variables have to be declared before they can be used. That is, they need to be explicitly referred to in the code, and possibly assigned a value. In a strongly typed language, the type of the variable has to be declared with the variable. For example, if we were going to use the variable yourName for the string Homer Simpson, we might use the following code in a strongly typed language:

let yourName:string = "Homer Simpson";

Get hands-on with 1200+ tech skills courses.