Introduction to JavaScript – Create a Variable: const

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

const myName = 'Seth';
console.log(myName);
// Output: Seth

Let’s consider the example above:

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

2) 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.

3) = is the assignment operator. It assigns the value (‘Seth‘) to the variable (myName).

4) ‘Seth‘ is the value assigned (=) to the variable myName.
After the variable is declared, we can print ‘Seth‘ to the console with console.log(myName).

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

const myAge = 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.


Introduction to JavaScript – Create a Variable: const


Related Videos:

MiltonMarketing.com Related Videos.

Related Links:

JavaScript Glossary: on Variables

W3Schools.com on JavaScript Variables

Online JavaScript Compiler. Code on the go.

JavaScript Glossary

My little pony learning game in VB.NET

Hello World Android app built with Android Studio

Introduction to JavaScript – Control Flow: if/else Statements

Introduction to JavaScript – Properties

Introduction to JavaScript – Create a Variable: let

Introduction to JavaScript – Data Types

Who is this Android App Development course for?

Android Studios

Introduction to JavaScript – Review Types and Operators

Why Python is the cooler programming language

Python Glossary

Introduction to JavaScript – Variables: Review

Why do most sites use cookies?

FAQs