Monday 16 December 2013

Javascript : Data types & Variable

JavaScript DataTypes:
Javascript support these types of data types:

JavaScript have three primitive data types:

-> Strings of text e.g. "Hello string" etc.
-> Numbers eg. 123, 3200 etc.
-> Boolean e.g. true or false.

JavaScript have two trivial data types :
-> null
-> undefined

JavaScript also supports a composite data type known as object.

JavaScript Variables:

JavaScript has variables.
Variables is actually a containers.
User 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,
User must declare it.
Variables are declared with the var keyword as follows:

<script type="text/javascript">

var data;
var employeename;

</script>

User declare multiple variables with the same var keyword as follows:

<script type="text/javascript">

var data,employeename;

</script>
Storing a value in a variable is called variable initialization.
User can do variable initialization at the time of its creation:

<script type="text/javascript">

var data = "hello how are you?";
var employeename = Abhi;

</script>
Note: Use the var keyword only for declaration or initialization.
         once for the life of any variable name in a document.
         Do not re-declare same variable twice.
         JavaScript is untyped language.
         it can hold a value of any data type.
         you don't have to tell JavaScript during variable declaration
         what type of value the variable will hold.

JavaScript Variable Scope:
JavaScript variable will have only two scopes.

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

Local Variables: A local variable will be visible only within a function where
                         it is defined.And it can be use only within that function scope
Following example explains it:


Javscript Reserved Keyword :

abstract,   boolean , break , byte ,  case  ,   catch,  char , class ,     const  , continue
debugger ,  default ,delete , do ,   double, else  , enum , export   ,  extends false
final   ,   finally , float ,  for ,  function , goto ,  if  ,  implements , import ,  in
instanceof ,  int  ,   interface ,   long  ,  native , new , null , package ,  private
protected ,  public ,  return , short , static , super , switch , synchronized , this
throw,  throws , transient , true , try ,  typeof , var ,  void ,  volatile ,  while , with

Note : User cannot use these keyword as variable name

      

No comments:

Post a Comment