Deprecated: Array and string offset access syntax with curly braces is deprecated in /home/u591492611/domains/codeone.in/public_html/application/third_party/google-login-api/service/apiUtils.php on line 58
CodeOne
CodeOne
JAVASCRIPT DATA TYPES  JAVASCRIPT DATA TYPES 
Monday, 31 May 2021 00:00 am
CodeOne

CodeOne

JAVASCRIPT DATA TYPES 

In javascript we define values to javascript variables we may define any value to that variable, if you want to know which type of data it is known by command of "typeof"

In JavaScript there are 7 types of data types are present 

Example to know the defined variable value is which data type:

<html> 
         <head>
    
          SCRIPT  

                   var x=10;

                   Document.write(typeof x);

         /SCRIPT

        </head>

        <body>

</html>

7 TYPES OF DATA TYPES ARE THERE

1. STRING [ String means charecters of sequence ]

    Example : 

   <html> 
                <head>
    
                                SCRIPT  

                                var x='AMD';

                                Document.write(typeof x);

                                /SCRIPT

                                                 [ or ]

                                SCRIPT  

                                var x='10';

                                Document.write(typeof x);

                                /SCRIPT

               </head>

               <body>

               </body>

</html>

OUTPUT : String [for both above scripts]  

Note : While you defining variable value if you define the value in Single quote or Double Quote that becomes string.

2.NUMBER

 Example : 

<html> 
                <head>
    
                                SCRIPT  

                                var x=10;

                                 var y=10.10;

                                Document.write(typeof x);

                                Document.write(typeof y);

                                /SCRIPT

                                                             
               </head>

               <body>

               </body>

</html>

OUTPUT : Number.

3.BOOLEAN

 Example : 

<html> 
                <head>
    
                                SCRIPT  

                                var x=true/false; [Output : Boolean]

                                var x=3>2;          [Output : True]

                                var x=2>3;          [Output : false]

                                Document.write(typeof x);

                                Document.write(typeof y);

                                /SCRIPT

                                                             

               </head>

               <body>

               </body>

</html>

OUTPUT : boolean

4.ARRAY

 Example : 

<html> 
                <head>
    
                                SCRIPT  

                                var x=['a','b'];
                                Document.write(typeof x);

                                 /SCRIPT

               </head>

               <body>

               </body>

</html>

OUTPUT : In any language if you print array data type that will give type as array, but in javascript while you print array data type it will gavie array data type as object [why t shows like this will discuss in array section].

5.OBJECT

Example : 

<html> 
                <head>
    
                                SCRIPT  

                                var x={'a':10,'b':15};
                                Document.write(typeof x);

                                /SCRIPT

               </head>

               <body>

               </body>

</html>


OUTPUT : OBJECT. [ Will discuss about it clearly in OOPS Concept.]

6.NULL

 Example : 

<html> 
                <head>
    
                                SCRIPT  

                                var x;
                                Document.write(typeof x);

                                /SCRIPT

                                                             

               </head>

               <body>

               </body>

</html>

OUTPUT: OBJECT.

7.UNDEFINED

Example : 

<html> 
                <head>
    
                                SCRIPT  

                                var x;

                                Document.write(typeof x);

                                /SCRIPT

                                                          

               </head>

               <body>

               </body>

</html>

OUTPUT : UNDEFINED.

These are the Main Data types which are using in JAVASCRIPT. [In case of  ARRAY,OBJECT,NULL you may have dought of output is getting as Data type of OBJECT but actually which type of data type it is actually we are not getting in future topics i will clearly explain about it keep following.