- Primitive Data Type
- Object Data Type
Primitive Data Type
ये चार प्रकार के होते हैं|
- String
- Number
- Boolean
- Undefined
Object Data Type
ये चार प्रकार के होते हैं|
- Null
- Array
- Function
- Object
String Primitive Data Type
यह एक characters का sequence होता हैं, String को double("") या single('')quotes में लिखा जा सकता हैं|
Q :- String Primitive Data Type in JavaScript.
Source Code :
<!DOCTYPE html> <html> <head> <title>String Primitive Data Type</title> </head> <body> <script type="text/javascript"> var str1='Hello'; //single quote string var str2="World"; //Double quto string var str3=""; //empty string document.write("Value of str1 is "+str1+"<br>"); document.write("Value of str2 is "+str2+"<br>"); document.write("Value of str3 is "+str3+"<br>"); </script> </body> </html>
Output :-
Value of str1 is Hello Value of str2 is World Value of str3 is
Number Primitive Data Type
JavaScript में सिर्फ एक ही Number Data type होता हैं| Number पर integer values और floating-point values होती हैं|
Q :- Number Primitive Data Type in JavaScript.
Source Code :
<!DOCTYPE html> <html> <head> <title>Number Primitive Data Type</title> </head> <body> <script type="text/javascript"> var a =5 // integer number value var b=6.10 // floating-point number value var c=-7 // negative number value var d=-8.5 // floating-point negative number value document.write("Value of a is "+a+"<br>"); document.write("Value of b is "+b+"<br>"); document.write("Value of c is "+c+"<br>"); document.write("Value of d is "+d+"<br>"); </script> </body> </html>
Output :-
Value of a is 5 Value of b is 6.1 Value of c is -7 Value of d is -8.5
Boolean Primitive Data Type
यह data type सिर्फ 'true' और 'false' value return करता हैं|
Q :- Boolean Primitive Data Type in JavaScript.
Source Code :
<!DOCTYPE html> <html> <head> <title>Boolean Primitive Data Type</title> </head> <body> <script type="text/javascript"> var a=10; var b=5; var c=(a<b); // a less than b document.write("Value of a is "+a+"<br>"); document.write("Value of b is "+b+"<br>"); document.write("a less than b : "+c+"<br>"); </script> </body> </html>
Output :-
Value of a is 10 Value of b is 5 a less than b : false
Undefined Primitive Data Type
Variable जब declare या initialize नहीं किया जाता हैं|तो वो 'Undefined data type' होता हैं|
Q :- Undefined Primitive Data Type in JavaScript.
Source Code :
<!DOCTYPE html> <html> <head> <title>Undefined Primitive Data Type</title> </head> <body> <script type="text/javascript"> var a; document.write("Value of a is "+a); </script> </body> </html>
Output :-
Value of a is undefined
Null Object Data Type
Null मतलब variable पर कोई value नहीं होती हैं, Null Undefined के बराबर होती हैं|
Q :- Null Object Data Type in JavaScript.
Source Code :
<!DOCTYPE html> <html> <head> <title>Null Object Data Type</title> </head> <body> <script type="text/javascript"> var a=null; // null var b; // undefined var c=(a==b); // equal value (true) var d=(a===b); // equal value and same type (false) document.write("a equal value b : "+c+"<br>"); document.write("a equal value and same type b : "+d); </script> </body> </html>
Output :-
a equal value b : true a equal value and same type b : false
Array Object Data Type
यह एक same data type का collection होता हैं, Array की values ([]) में दी जाती हैं हर array की value comma(,) से seperate की जाती हैं|
Q :- Array Object Data Type in JavaScript.
Source Code :
<!DOCTYPE html> <html> <head> <title>Array Object Data Type</title> </head> <body> <script type="text/javascript"> var arr=[1,2,3,4,5]; document.write("arr[0] : "+arr[0]+"<br>"); document.write("arr[1] : "+arr[1]+"<br>"); document.write("arr[2] : "+arr[2]+"<br>"); document.write("arr[3] : "+arr[3]+"<br>"); document.write("arr[4] : "+arr[4]+"<br>"); </script> </body> </html>
Output :-
arr[0] : 1 arr[1] : 2 arr[2] : 3 arr[3] : 4 arr[4] : 5
Function Object Data Type
function को create करने के लिए 'function' keyword का use किया जाता हैं, function Statements का एक block होता हैं|
Q :- Function Object Data Type in JavaScript.
Source Code :
<!DOCTYPE html> <html> <head> <title>Function Object Data Type</title> </head> <body> <script type="text/javascript"> function fun(){ var x=5; document.write("Value of x is "+x); } fun(); </script> </body> </html>
Output :-
Value of x is 5
Object : Object Data Type
JavaScript में object को use करने के लिए methods और properties का use किया जाता हैं|
Q :- Object Object Data Type in JavaScript.
Source Code :
<!DOCTYPE html> <html> <head> <title>Object Object Data Type</title> </head> <body> <script type="text/javascript"> var student={ roll_no : 1, name : "Ravi Kumar", address : "Raipur", }; document.write(student.roll_no+"<br>"); document.write(student.name+"<br>"); document.write(student.address); </script> </body> </html>
Output :-
1 Ravi Kumar Raipur
Post a Comment
If you have any doubts,Please let me know