What is Variable? How to declare? and Legal and Illegal variables declaration in JavaScript?

Sadiq Shah - May 22 '22 - - Dev Community

What is variable ?

Variables is the placeholder or the box, container that contains the values i.e. Letter(Strings), Number(integers, decimal), Characters(Special Symbol), Boolean(true and false), Object etc.

Data type :

Data type which defines the variable type or what kind of value can be store in the variable.(integer, string, number, symbol, Boolean, Object etc.)

How you can declare the variable in JavaScript

keyword specifier/Identifier = value (Data type)

Example :

var name = "Sadiq Shah";
var age = 23;
Enter fullscreen mode Exit fullscreen mode

(I pass the value string to the variable named as name and age into number)

What is Legal and Illegal variable in JS?

Legal Variables : Can be declare

  var myname = "Sadiq Shah";
    var myName = "Sadiq Shah";
    var my_name = "sadiq shah";
    var _my_name = "sadiq shah";
    var $my_name = "sadiq shah";

Enter fullscreen mode Exit fullscreen mode

Illegal Variables : Can not be declare

  var @myname = "Sadiq Shah";
    var 123myName = "Sadiq Shah";
    var my name = "sadiq shah";
    var month&year = "saadiq shah";
    var birth-year = "1990";

Enter fullscreen mode Exit fullscreen mode
. . . . . .
Terabox Video Player