In Javascript there are legal and illegal ways of naming a variable:
Legal way:
Must
begin with a letter, underscore (_), or dollar sign ($).
Can contain letters, numbers,
underscores, or dollar signs.
Are case sensitive, meaning that "myVar" and "myvar" are two different
variables.
Should
not use reserved keywords, such as "var", "function", "if", "else",
"while", "for", etc.
Illegal variable names:
Cannot begin with a number.
Cannot contain spaces or special characters (except underscore or dollar
sign).
Cannot use reserved keywords.
Cannot start with Capital letters.
CamelCase is reccomended to use in Js => myFullname, isMarried...
const PI = 3.14; This variable works only in this case.
Naming variables must be descriptive:
const myFirstName = "Mirjalol";
cosnt myFirstJob = "Teacher"
Variables that
hold a value can be data type, not variable.
This is multi
line way of commenting
Single line way of commenting
let, var and const
let can be reassigned, mutated.
let book = "Alvido Vatan";
book = "Halol Luqma";
✅
let cannot be redaclared
let myFirstJob = "Teacher";
let myFirstJob = "Programmer";
❌
You can create Undefined variable with let.
let code;
✅
Reccomanded
one is const
variables that doesnt change are declared with const, u cannot reassign and
redaclare