Variables and Data Types used in JavaScript.


Variables and Data Types used in JavaScript.

  • Variables
    • Definition of variable 
    • Rules for variable declaration
    • Example of variable
  • Data Types
    • Definition of data type
  • Different types of Data types
    • 1.Number
    • 2.String
    • 3.Boolean
    • 4.null
    • 5.undefined
    • 6.infinity

Variable declaration in JavaScript

        A variable is symbolic name to store a value.

Rules for valid variable names are as follows-

    1.    A variable must begin with alphabets only.     2.    A variable name contains alphabets with uppercase and lowercase and digits i.e. 0 to 9  and underscore character.

    3.    Special characters are not allowed i.e.!,@,#,!123 etc.     4.    In JavaScript variable names are case sensitive i.e. uppercase and lowercase letters  are not same i.e.PQR is not same as we written pqr.     5.    Keywords are not used e.g.while,if,switch ,function etc.     6.    A name given to variable is maximum upto 255 characters.

    In JavaScript variable names are declared by using keyword “var”.

 Syntax:       var variable_name;       var variable_name1,variable_name2;

        In JavaScript to assign a value to a variable assignment operator is used i.e.equal to (=).                 e.g. var variable_name=value;

Example:             var a;    var a,b,c,d;             var a=15,b=15;

Example-

 <!doctype html>  <html>  <head>

<title>Area of Triangle</title>

</head> <body> <script language="javascript">

var b,h,area; b=1; h=1; area=0.5*b*h;

document.write("Area of Triangle="+area);

 </script>  </body></html>     

 Data Types-                         

        In every programming language data type plays an important role. Each            variable must have a data type.We use variables To store values. The data types     assigned to variables determines values and operations performed on it. Here data    types which are used in programs offers definition, implementation and how they    are used.

Different data types used in JavaScript are given below-

1.Number-    

        This number data type contains numerical values. Number data type contains both whole numbers or decimal numbers i.e. whole number means integer without fraction part and decimal numbers means floating point numbers with decimal point. Numerical values are stored in this number data type.     e.g.var a=10; var b=6.5;

 2.String -

         String types are used to store sequence of characters i.e. String. String data             types values are assigned to variable by using single quote or double quote.            e.g.var sms=”message”;

var x=”Welcome to IT”; 3.Boolean -

         In this data type, only two values true or false. In programming we use logical        operators, conditional and relational operators all produce result true of false i.e. Boolean values.

4.null-

           When we want to give values which contain something i.e.does not exist means ‘nothing’,’empty’ or ‘unknown’.  

5.undefined-

         When in programming we declared variable but not assigned it gives result undefined.       

6.infinity-

           when we divide any value by 0 it result infinity.


Click Video for Variables and Data Types

Click Video for Introduction of javascript

🏠Home


https://itquizcontent.blogspot.com
Previous
Next Post »

Please Comment and Share. ConversionConversion EmoticonEmoticon