WHAT'S NEW?
Loading...

Java Script - Part 03

JavaScript DataTypes:

JavaScript allows you to work with three primitive data types:

  1. 1. Numbers eg. 123, 120.50 etc.
  2.  
  3. 2. Strings of text e.g. "This text string" etc.
  4.  
  5. 3. Boolean e.g. true or false.

JavaScript also defines two trivial data types, null and undefined, each of which defines only a single value.

JavaScript Variables:
Like many other programming languages, JavaScript has variables. Variables can be thought of as named containers. You can place data into these containers and then refer to the data simply by naming the container.

Before you use a variable in a JavaScript program, you must declare it. Variables are declared with the var keyword as follows:


<script type="text/javascript"> 

<!-- 
var money; var name; 
//-->
 </script>

JavaScript Variable Scope:
The scope of a variable is the region of your program in which it is defined. JavaScript variable will have only two scopes.

1.  Global Variables: A global variable has global scope which means it is defined everywhere in your JavaScript code.

2.  Local Variables: A local variable will be visible only within a function where it is defined. Function parameters are always local to that function.

JavaScript Variable Names:While naming your variables in JavaScript keep following rules in mind.


  • 1.  You should not use any of the JavaScript reserved keyword as variable name. These keywords are mentioned in the next section. For example, break or boolean variable names are not valid.
  •  
  • 2.  JavaScript variable names should not start with a numeral (0-9). They must begin with a letter or the underscore character. For example, 123test is an invalid variable name but _123test is a valid one.
  •  
  • 3.  JavaScript variable names are case sensitive. For example, Name and name are two different variables.
 

0 comments:

Post a Comment