The basics of variables in JavaScript.

Natalia Wit
1 min readSep 13, 2020

--

A variable in JavaScript is like a box we can store things inside for later retrieval. A variable can hold any type of data such as a number, string, true/false, or even an object. We store data inside a variable and hand it off to JavaScript that stores this data in memory. It will also always be stored until we need to access it anytime again.

To know what data to retrieve we need to label our box. In other sense, you need to label your variables.

Rules to follow when naming your variables

If you follow these rules when naming your variables you shouldn’t run into any issues.

  1. You should start your variable with a lowercase letter and they should not start with a number EVER
  2. You should never use spaces, you should camel case your variables like this — camelCaseYourVariable. This is the rule with JavaScript variables.
  3. You should never use JavaScript reserved words.

Initializing you’re variables in JavaScript

You can initialize your variable in JavaScript with var, let, and const. In order to assign something to a variable, it needs to be initialized first.

--

--

No responses yet