AlgoritmaCSSEğitimHTMLJavaScriptPHPProgramlama DiliTeknolojiYazılım

JavaScript Variables #1

This lesson over subject is what is the JavaScript Variables. I hope this lesson is useful for you.

JavaScript Variables

Variable means aynithing that can vary. JavaScript inculudes variables hold the data value and it can be changed ayntime.

JavaScript uses reserved keyword var to declare a variable. A variable must have a unique name. You can assign a value to a variable using equal to (=) operator when you declare it or before using it.


Example: Variable declaration & initialization:

In the above example, we have declared three variables using var keyword: one, two and three. We have assigned values to variables one and two at the same time when we declared it. whereas variable three is declared but does not hold any value yet, so it’s value will be ‘undefined’.

Declare Variables in a Single Line

Multiple variables can also be declared in a single line separated by comma.


Declare a variable without var keyword

JavaScript allows variable declaration without var keyword. You must assing a value when you declare a variable without var keyword.


It is Not Recommended to declare a variable without var keyword. It can accidently overwrite an existing global variable.

Loosely-typed Variables

C# or Java has strongly typed variables. It means variable must be declared with a particular data type. which tells what type of data the variable will hold.

JavaScript variables are loosely-typed which means it does not require a data type to be declared. You can assign any type of literal values to variable e, g, string, integer, float, boolean etc……..

Points to Remember:

  • Variable stroes a single data value that can be changed later.
  • Variables can be defined using var keyword. variables defined without var keyword become global variables.
  • Variables must be initialized before using.
  • Multiple variables can be defined in a single line e, g, var = 1, two = 2, three = “three”;
  • Variables in JavaScript are loosely-typed variables. It can store value of any data type through out it’s life time.

I hope this lesson is helpful to you.
Always be happy and proud.
And don’t give up trying



Adım Amin, Soyadım Aslami 21 yaşındayım Afgnistanlıyım herat'ten Fırat Ünv. Yazılım Müh. 2. Sınıf Yazar Name and Family name: Amin Aslami From Afghinstan Herat Firat Unv. Software Eng. 2.Class Writiter

İlgili Makaleler

Bir Cevap Yazın

Başa dön tuşu
%d blogcu bunu beğendi: