In Projects, you can keep track of your progress as you go throught the tasks. Check each item as you complete it!

Code Editor

Reset Exercise

Learn

Variables

Create a Variable: const

Let's dive in and see a variable in the wild. Here is how you declare a constant variable:

constmyName='Arya';
console.log(myName);
// Output: Arya

Let's consider the example above:

const, short for constant, is a JavaScript keyword that creates a new variable with a value that cannot change.

myName is the variable's name. Notice that the word has no spaces, and we capitalized the N. Capitalizing in this way is a standard convention in JavaScript called camelCasing, because the capital letters look like the humps on a camel's back.

= is the assignment operator. It assigns the value ('Arya') to the variable (myName).

'Arya' is the value assigned (=) to the variable myName.

After the variable is declared, we can print 'Arya' to the console with: console.log(myName).

You can save any data type in a variable. For example, here we save numbers:

constmyAge=11;
console.log(myAge);
// Output: 11

In the example above, on line 1 the myAge variable is set to 11. Below that, console.log() is used to print 11 to the console.