Search⌘ K
AI Features

Variables

Explore JavaScript variables by learning how to assign values, distinguish between primitive and reference types, and understand type changes during execution. This lesson helps you grasp key concepts about value storage and variable behavior in JavaScript.

As you learned earlier, JavaScript supports objects that can have dynamic properties, and so they can be used to represent compound things.

JavaScript also supports primitive or simple value types that store irreducible values such as numbers, strings, and Boolean flags. In this section, you will learn more about these values and types.

Variable assignment #

To store either simple values or objects, you must assign them to variables:

Node.js
var obj = new Object();
obj.name = "Dave";
var number = 42;
var regExp = /(bat)?man/;

Here, obj and regExp variables hold object instances (a regular expression is represented by a RegExp ...