Myvar = 12;
In the above snippet, we declare a variable called
2. The Declare Variable Example
The example is in the below screenshot. You can use any editor type the code and save it as 001_DeclareVariable.html:
1) Within the
body tag, we have a pair of
2) In the first code snippet, we declared a variable called
MyVar. Using the assignment operator =, we stored a string value in the
MyVar. Then, using the
alert function, we display the content of the
MyVar in a message box. Note how semicolon in separating each statement for easy readability. But the usage of the semicolon to separate the statement is optional.
1) Let us assume that you saved the file 001_DeclareVariable.html at C:\Temp folder.
2) Open Google Chrome Browser
3) Navigate to the Folder C:\Temp
4) Drag & Drop the File 001_DeclareVariable.html to Chrome Browser
5) The browser shows the Message Box thrown by the alert call. Message box shows the MyVar variable content:
6) Click OK on to the message box. The second alert display which shows the MyVar variable’s updated content:
4. Code Reference
<title>Declare and Use variables</title>
//Sample 01: Read and Write Variable
var MyVar = "Some String";
//Sample 02: Reuse Same variable with Different Type
MyVar = 108;
Do you like this Example? Please comment about it for others!!