DEV Community

Dharchini
Dharchini

Posted on

Declaration and Usage of Variables in JavaScript

In JavaScript, variables are specified using one of three syntaxes. By providing the grammar template for creating variables, I can illustrate them. A syntax template is a generalized form of a JavaScript component or phrase.

The rules for creating variables must be reviewed before we go on to the how-to.

Variables can start with a symbol, numeric, or underscore characters. A variable name should always start with an alphabetic letter in programming.

The variables may have additional alphabetic, numeric, or symbol characters after the first character. Making your variable names relevant is the secret to good variable naming, unless the variable is only used very briefly and insignificantly.

The three syntax templates for declaring new variables are:

let variable-name = expression;
var variable-name = expression;
const variable-name = expression;

What sets apart these three approaches to defining variables, you might wonder. Two of them are connected to the idea of "changing scope," The other version, which starts with const, will remain the same and can't be changed.

Top comments (1)

Collapse
 
smartjeff profile image
Jeff Odhiambo

Nice one