| What is Data Type & Variables? | ||
| String | ||
| String type deals with a single character or a series of characters enclosed with single quotes or double quotes respectively. | ||
| Initializing string type variables | ||
| var sect = 'a' | ||
| var is JavaScript keyword, sect is a variable name, a is value assigned to sect variable, variable sect is of string type because the value assigned to sect is of string type. | ||
| var country="India" | ||
| var is JavaScript keyword, country is a variable name, India is value assigned to country variable, variable country is of string type because the value assigned to country is of string type. | ||
| In the example given below we have used keyword document.write (message ) which is used to print the message or variable value given with it. | ||
| Example 1 | ||
|
<html> <head> </head> <body> <script type="text/JavaScript"> var sect=’a’ document.write("Section is : "+sect); </script > </body> </html> |
||
| Understanding the program | ||
| <script > tag is the start of a JavaScript program, var is to declare a variable of name sect and ‘a’ is the value assigned to the variable sect. document.write is used to print the given message and/or value of a given variable. We have used + sign here which is used to concatenate the message ( Section is : ) and the value of variable sect (a). | ||
| Output of this program | ||
| sectoion is : a | ||
| Click here to run this program in browser | ||
| Example 2: | ||
|
<html> <head> </head> <body> <script type="text/JavaScript"> var country=’India’ document.write("Country is : "+country); </script > </body> </html> |
||
| Understanding the program | ||
| <script > tag is the start of a JavaScript program, var is to declare a variable of name country and “India” is the value assigned to the variable country. document.write is used to print the given message and/or value of a given variable. We have used + sign here which is used to concatenate the message ( Country is : ) and the value of variable country (India). | ||
| Output of this program | ||
| Country is : India | ||
| Click here to run this program in browser | ||
|
||