- Declaring a variable
- Giving it a unique name
- Assign a value to your variable
Rules you must follow while working with variables in JSWell there are few rules in JS which you must follow like
- You must begin with a letter,$ or _ That means Ved, My_Num, $My_pay, _NewYork are correct but 1india,%bills,*Jesus are not
- Your variable name must contain number,$,letters and _ You can’t use spaces or any other special characters anywhere in the variable name: fish&chips and fish and chips aren't legal, but fish_n_chipsand plan9are.
Assigning VariablesTo assign a variable you must declare a variable then give it a unique name and in last give it a value like
var my_age = 22;Here Var is keyword , my_age is the unique name and 22 is the value of variable my_age