Search⌘ K

Variables

Explore the core concept of variables in JavaScript, including their properties, how to declare and assign them, and the significance of variable scope. This lesson helps you grasp data storage in programs and dynamic typing to build foundational coding skills.

Role of a variable

A computer program stores data using variables. A variable is an information storage area. We can imagine it as a box in which you can put and store things!

Variable properties

A variable has three main properties:

  • Its name, which identifies it. A variable name may contain upper and lower case letters, numbers (not in the first position), and characters like the dollar sign ($) or underscore (_).
  • Its value, which is the data stored in the variable.
  • Its type, which determines the role and actions available to the variable.

You don’t have to define a variable type explicitly in JavaScript. Its type is deduced from the value stored in the variable and may change while the ...