JavaScript Data Types

 JavaScript Data Types

1) String :

which are used to store the data that involves the characters

Example: var x=” Hello World”;

Program:

<!DOCTYPE html>
<html>
 <body>
  <script>
   var x="Hello world";
   document.write(x);
   document.write("<br>");        
   document.write(typeof x);
  </script>
 </body>
</html>

Output:

Hello world

String

2) Numbers :

a numbers can be written with or without decimal

Example

<!DOCTYPE html>
<html>
 <body>
  <script>
   var x=25;
   document.write(x);
   document.write("<br>");        
   document.write(typeof x);
  </script>
 </body>
</html>

Output:

25

Numbers

3) Boolean:

it represent a logical entities like true or false

Example:

<!DOCTYPE html>
<html>
 <body>
  <script>
   var x=True;
   document.write(x);
   document.write("<br>");        
   document.write(typeof x);
  </script>
 </body>
</html>

Output:

True

Boolean

Example: if you write True in Single or Double Quote it will be treated as string

<!DOCTYPE html>
<html>
 <body>
  <script>
   var x="True";
   document.write(x);
   document.write("<br>");        
   document.write(typeof x);
  </script>
 </body>
</html>

Output:

True

Boolean

4) Arrays:

It can be written in a square bracket and it is separated by commas.

Example:

<!DOCTYPE html>
<html>
 <body>
  <script>
   var x=[“seema”, “,35”,”44”];
   document.write(x);
   document.write("<br>");        
   document.write(typeof x);
  </script>
 </body>
</html>

 Output:

Seema 25 44

Array

5) Objects:

it is a value in a memory , it is refereed by identifier .
Example:

<!DOCTYPE html>
<html>
 <body>
  <script>
   var x=[44,35];
   document.write(x);
   document.write("<br>");        
   document.write(typeof x);
  </script>
 </body>
</html>

Output:

44 35

Objects

6) Null:

it has exactly only one value.
Example:

<!DOCTYPE html>
<html>
 <body>
  <script>
   let age = null;
   consloe.log("age is "+age);  
  </script>
 </body>
</html>

Output:

Age is nulls

7) Undefined :

a variable that has not assigned any value;
Example:

<!DOCTYPE html>
<html>
 <body>
    <script>
        var x;
        document.write("<br>");       
        document.write(typeof x);
    </script>
 </body>
</html>

Output:

Undefined