Data Types in Javascript in Hindi – जावास्क्रिप्ट डाटा टाइप्स

javascript data types in hindi

data types किसी variable में किस तरह की डाटा है वो दर्शाता है | javascript एक dynamic programming language है | जब JS code run होता है उस समय variable में assign value के हिसाब से variable की datatype js engine decide करता है |

javascript में variables var keyword से define की जाती है | इसीलिए इसमें जो भी value दी जाती है वो run time में उसकी datatype को बताती है |

javascript में data types इस प्रकार होतें हैं

  1. string
  2. number
  3. boolean
  4. object
  5. undefined

string datatype

string data type में variable की data sequence of characters को represent करता है | string datatype में data को single quotes या double quotes के अंदर लिखी जाती है |

नॉटपॉइंट : अगर data को single quote से सुरु किया है तो single quote से बंद करना होगा और अगर double quote से सुरु किया गया है तो double quote से बंद करना होगा |

उदाहरण

var fname="Minu";
var a="abc";
var b='delhi';

number datatype

number चाहे वो integer हो या float इन सभी data को javascript number consider करता है |

उदाहरण

var num1= 123;
var num2= 3.14;

boolean datatype

true या false value को boolean datatype कहा जाता है |

उदाहरण

var res=true;

object datatype

array, object और null ये सारे data को javascript object data type के रूप में consider करता है |

array data type

एक variable में multiple values को store करने के लिए array का इस्तेमाल होता है | array में data को [ ] (square brackets) के अंदर लिखी जाती है | और values को ,(comma) से अलग करके लिखी जाती है |

उदाहरण

var arr = ["sun", "mon", "tue", "wed"];
var numarr = [10, 20, 30, 50];

object data type

object data type में data को name value pairs में लिखी जाती है |

उदाहरण

var userdetail = {"name":"Arorhi", age:22, "address":"new delhi"};

null data type

null का मतलब होता no value यानि variable में कोई value नहीं है | वो अभी खाली है |

undefined data type

जब किसी variable को सिर्फ declare करदें और उसमे कोई भी value नहीं दी जाए तो उसकी data type को undefined कही जाती है |

उदाहरण

var a;

typeof का उपयोग क्या है?

typeof keyword के जरिये किसी value या variable की datatype जानने के लिए उपयोग होता है |

Syntax:
typeof [variablename];
typeof [value];

typeof से variable name या फिर direct value डालकर उसकी data type पता लगायी जा सकती है |

उदाहरण

<!doctype html>
<html>
 <head>
  <title>data types in javascript</title>
 </head>
 <body>
  <script>
    var a, b, c, d;
    a="minu";
    b=22;
    c=true;
    document.write("datatype of a is ", typeof a);
    document.write("<br> datatype of b is ", typeof b);
    document.write("<br> datatype of c is ", typeof c);
    document.write("<br> datatype of d is ", typeof d);
    document.write("<br> datatype of NULL is ", typeof null);
  </script>
 </body>
</html>

output

data type in javascript

notepoints

अगर कोई data चाहे वो characters हो या नंबर हो या फिर boolean, अगर उसे quotes के अंदर लिखी गयी तो उस data की data type string बन जायेगी |

इसीलिए जिस data की data type string रखनी है उसे quotes के अंदर लिखी जाती है | और number, boolean data को बिना quotes के लिखी जाती है |

उदाहरण

<!doctype html>
<html>
 <head>
  <title>data types in javascript</title>
 </head>
 <body>
  <script>
    var a = 20;
	var b = "20";
	var c = true;
	var d = "true";
	document.write("datatype of a is ", typeof a);
	document.write("<br> datatype of b is ", typeof b);
	document.write("<br> datatype of c is ", typeof c);
	document.write("<br> datatype of d is ", typeof d);
  </script>
 </body>
</html>

output

null और undefined में क्या अंतर है ?

null : null यानि no value | अगर किसी variable की value को null रख दी जाए तो उसकी datatype object होगी | पर उसकी value कुछ भी नहीं होगी | वो एक खाली variable होगा |

undefined: undefined datatype में variable की datatype अनजान(unknown) होती है | अगर variable को सिर्फ declare कर दिया जाए तो उस variable की datatype undefined कह लाएगी |

अन्य javascript tutorial के सुझाव