freeCodeCamp Challenge Guide: Declare JavaScript Variables

Declare JavaScript Variables


Hints

Hint 1

When we store data in a data structure, we call it a variable. JavaScript variables are written in camel case. An example of camel case is: camelCase.

You can declare a variable this way

var myName = "Rafael";

ES6 introduced two other ways to declare variables. let and const. Let is pretty similar to var and for the most part is interchangeable:

let myAge = 36;

Where let differs, is in its scope. When we declare using var, it’s global in scope. When we declare using let, the scope is limited to that function. If you want to use a let variable outside a function, you have to make it global in scope or redeclare it in the next function.

const, on the other hand, can only be declared once. Its value can never change.


Solutions

Solution 1 (Click to Show/Hide)
var myName;
10 Likes