Wednesday, 22 August 2018

Javascript: Variables

Variable holds a value. Following are some of the examples of variables.

var name = "Krishna"
var id=123

Above statements define two variables name, id. ‘var’ keyword is used to define variables.

Naming constraints
a.   Variable name must begin with any alphabet, _ (or) $.
b.   Variable name can contain any character.
c.   Spaces are not allowed in between variable names.
d.   Don’t use Javascript keywords as variable names.
e.   Variable names are case sensitive. Name, NAme, name are 3 different variables.

variables.html

<!DOCTYPE html>

<html>
 <head>
  <title>Variables</title>
 </head>
 
 <body>
  <script type="text/javascript">
   var name = "Krishna";
   var id=123;

   document.write("name = " + name + "<br />");
   document.write("id = " + id);
  </script>
 </body>
</html>


Note
Java script is case sensitive, so the names banana, Banana, BaNaNa are three different variables.


Previous                                                 Next                                                 Home

No comments:

Post a Comment