Thursday 15 May 2014

JavaScript Variables and DataTypes:By Amit Tiwari

JavaScript DataTypes:-


There is the most fundamental characteristics of a programming language is the collection ofdata types it supports. These are the type of values that can be represented and manipulated in a programming language.

JavaScript always allows you to work with 3 primitive data types:


1)Numbers eg. 123456, 123.50 etc.

2)Strings of text e.g. "This text is string" etc.

3)Boolean e.g. true or false.

JavaScript also defines two trivial data types:


1)Null
2)Undefined,

Each of which defines only a single value.

In addition to these primitive data types, JavaScript supports a composite data type known as object.

Note: Java does not make a distinction between integer values and floating-point values. All numbers in JavaScript are represented as floating-point values. JavaScript represents numbers using the 64-bit floating-point format defined by the IEEE 754 standard.

JavaScript Variables:


Variable can have short names (like x and y) or more descriptive names (age, sum, totalVolume).

-Variable names must begin with a letter.
-Variable names can also begin with $ and _ (but we will not use it)
-Variable names are case sensitive (y and Y are different variables)





















The Scope Of JavaScript Variable.


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

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

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

Within the body of a function, a local variable takes precedence over a global variable with the same name. If you declare a local variable or function parameter with the same name as a global variable, you effectively hide the global variable. Following example explains it:


<script type="text/javascript">
<!--
var myVar = "global"; // Declare a global variable
function checkscope( ) {
   var myVar = "local";  // Declare a local variable
   document.write(myVar);
}
//-->
</script>

Output Is,




Note-In this above hope you get all the information about javascript variables and data types.If you have any doubt or if you want to ask something else ask freely just comment in comment box i ll response you asap.

Posted by Amit Tiwari

2 comments:

  1. WOW AMAZING this article is very usefull for me thanks..
    Visits back http://malikmal98.blogspot.com

    ReplyDelete
  2. Thankyou IKMALIL....If you want to know any doubt ..just mail me on amittiwari92.ies@gmail.com or just comment here..i ll reply you .....take care

    ReplyDelete