Javascript | Data Type | Primitive Data Type By. Shivansh Sir
JAVASCRIPT
JAVASCRIPT | STRING
String ये Characters का sequence होता है | String को single या double quotes के अन्दर लिखा जाता है |
var str1 = 'SUNRISE';
var str2 = "COMPUTER";
JAVASCRIPT | STRING | EMPTY STRING
var str3 = "";
Strings को दो प्रकार से create किये जाते है |
String Type
String Object Type
var str4 = "WELCOME TO SUNRISE COMPUTER"; //String Type
var str5 = new String("WELCOME TO SUNRISE COMPUTER"); //String Object Type
Check Strings Equal or Not using '==' Operator
'==' Operator से दोनों Strings equal है |
Source Code
true
Output
true
Check Strings Equal or Not using '==' Operator
'===' Operator से दोनों Strings equal नहीं है, क्योंकि उनके data types अलग-अलग है |
Source Code
false
Output
false
Example
तो double quoted String में double quoted String दिया हुआ है | इससे String access नहीं होता |
var str = "WELCOME TO "SUNRISE" COMPUTER";
document.write(str);
Notes :- यदि double quoted string के अन्दर single quoted और single quoted string के अन्दर double quoted string हो तो वो access हो जाता है |
Source Code
WELCOME TO 'SUNRISE' COMPUTER
WELCOME TO "SUNRISE" COMPUTER
Output
WELCOME TO 'SUNRISE' COMPUTER
WELCOME TO "SUNRISE" COMPUTER
Notes :- अगर single quoted string के अन्दर single quoted string और double quoted string के अन्दर double quoted strig को access करने के लिए पहले escape character (\) का इस्तेमाल करना पड़ता है | अगर String में special characters को executes करना हो तो special characters से पहले escape character(\) का इस्तेमाल करना पड़ता है |
Source Code
WELCOME TO "SUNRISE" COMPUTER
WELCOME TO 'SUNRISE' COMPUTER
Output
WELCOME TO "SUNRISE" COMPUTER
WELCOME TO 'SUNRISE' COMPUTER
JAVASCRIPT | STRING | STRING LENGTH PROPERTY
String की length ये बहुत ही महत्वपूर्ण property है |
Source Code
11
Output
11
Javascript में String के लिए कुछ methods दिए गए है |
1. charAt() :- Index का character return करता है |
2. charCodeAt() :- Index के character की Unicode value में return करता है |
3. concat() :- दो string या दो से ज्यादा string को जोड़ने के लिए इस्तेमाल किया जाता है |
4. endsWith() :- String या character से String का end हुआ है या नहीं हुआ है इससे boolean value को return करता है |
5. fromCharCode() :- Unicode value से character को return करता है |
6. indexOf() :- Characters का first occurrence का index return किया जाता है |
7. lastIndexOf() :- Characters का last occurrence का index return किया जाता है |
8. localeCompare() :- दो String को locale में compare किया जाता है | ये 0, 1 या -1 return करता है |
9. repeat() :- Number तक String को repeat करके return किया जाता है |
10. replace() :- String से substring को regular expression से या नए string से replace किया जाता है |
11. search() :- Regular expression या string को search करके उसका index return किया जाता है | अगर search नहीं होता तो -1 return होता है |
12. slice() :- Startindex से endindex तक नए String को return किया जाता है |
13. split() :- Character से string को split करके array return किया जाता है |
14. startsWith() :- String की शुरुआत दिए हुए character या substring से हुई है या नहीं हुई है ये boolean value में return किया जाता है |
15. substr() :- String से दिए हुए index से उसके दिए हुए length तक substring को return किया जाता है |
16. substring() :- String से दिए हुए startindex से endindex तक substring को return किया जाता है |
17. toLowercase() :- String को lowercase में return किया जाता है |
18. toString() :- string object को string में return किया जाता है |
19. toUpperCase() :- String को uppercase में return किया जाता है |
20. trim() :- String से शुरुआत और आखिर के spaces को trim किया जाता है |
_________________________________________________________
JAVASCRIPT | NUMBER
Javascript में Number Object; Numbers पर control करता है | कुछ Number Integer होते है, तो कुछ Numbers Floating-point Numbers होते है | इन Numbers पर operation करके Integer Numbers को Floating-point Numbers भी बनाया जाता है और Floating-point Numbers को Integer भी बनाया जाता है | Number का Object और Constructor create किया जा सकता है |
var object_name = new Number(number);
Javascript में Number के लिए कुछ methods दिए गए है |
1. MAX_VALUE :- यहाँ पर Javascript में सबसे बड़ी value होती है |
2. MIN_VALUE :- यहाँ पर Javascript में सबसे छोटी value होती है |
3. NaN :- ये Not a Number Value होती है |
4. NEGATIVE_INFINITY :- ये Negative Infinity value होती है (-infinity)
5. POSITIVE_INFINITY :- ये Positive Infinity value होती है (infinity)
6. Number() :- Type को Number में convert किया जाता है |
7. parseFloat() :- parameter के parse करके floating-point Number return किया जाता है |
8. parseInt():- parameter के parse करके integer Number return किया जाता है |
9. isFinite() :- Number Finite है या नहीं ये check किया जाता है और boolean value return की जाती है |
10. isInteger() :- Number Integer है या नहीं ये check किया जाता है और boolean value return की जाती है |
11. toNaN() :- Number है या नहीं ये check किया जाता है और boolean value return की जाती है |
12. toExponential() :- number को exponential notation में उसका string return किया जाता है |
13. toFixed() :- number को fixed-point notation में उसका string return किया जाता है |
14. toPrecision() :- number को दिए हुए precision में उसका string return किया जाता है |
15. toString() :- number को string में convert करके return किया जाता है |
16. valueOf() :- Number Object को primitive value में convert किया जाता है |
_________________________________________________________
JAVASCRIPT | BOOLEAN
Boolean 'true' और 'false' ये दो values होती है |
<script type="text/javascript">
var a = true;
var b = false;
</script>
_________________________________________________________
JAVASCRIPT | UNDEFINED
Variable जब declare या initialize नहीं किया जाता तो वो 'undefined' data type होता है |
Source Code
<script type="text/javascript">
var a;
document.write("Value of a is " + a);
</script>
Output
Value of a is undefined
For Any Doubt Clear on Telegram Discussion Group
Comments
Post a Comment