Declare a Variable in JavaScipt Example

Updated on     Kisan Patel

In JavaScirpt we can declare the variable using the reserved word var. The value of this variable can be any thing; it can be numeric or it can be string or it can be a Boolean value.

var c = "Hello";

Variables are case sensitive and must start with an alphabet letter or a underscore (_).

var firstName;
var siteName = "C#";
lastName = "Code";
document.write(siteName + " " + lastName);

In the above code snippet
The 1st line declares the firstName variable.
The 2nd line declares the siteName variable and assign value.
The 3rd line assigns a value to undeclared variable that automatically creates a valid variable.


JavaScript

Leave a Reply