From 79b9f1ab35a673ff6a0658b68664a6b6137ffa7f Mon Sep 17 00:00:00 2001 From: Rishav Jadon Date: Fri, 2 Oct 2020 20:29:14 +0530 Subject: [PATCH 01/22] Create article1.md --- 1-js/02-first-steps/09-comparison/article1.md | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 1-js/02-first-steps/09-comparison/article1.md diff --git a/1-js/02-first-steps/09-comparison/article1.md b/1-js/02-first-steps/09-comparison/article1.md new file mode 100644 index 000000000..201676866 --- /dev/null +++ b/1-js/02-first-steps/09-comparison/article1.md @@ -0,0 +1,52 @@ +# तुलना + +हम गणित से कई तुलना ऑपरेटरों को जानते हैं। + +जावास्क्रिप्ट में वे इस तरह लिखे जाते हैं: + +- ग्रेटर / से कम: ए> बी, ए <बी। +- ग्रेटर / से कम या बराबर: ए> = बी, ए <= बी। +- समतुल्य: a == b, कृपया दोहरे समानता चिन्ह पर ध्यान दें == का अर्थ है समानता परीक्षण, जबकि एकल a = b का अर्थ है असाइनमेंट। +- नहीं के बराबर है। गणित में अंकन ≠ है, लेकिन जावास्क्रिप्ट में इसे a =! B लिखा जाता है। + +इस लेख में हम विभिन्न प्रकार की तुलनाओं के बारे में अधिक जानेंगे, कि कैसे जावास्क्रिप्ट उन्हें महत्वपूर्ण विशिष्टता सहित बनाता है। +अंत में आपको "जावास्क्रिप्ट क्विर्क" से संबंधित मुद्दों से बचने के लिए एक अच्छा नुस्खा मिलेगा। + +# बुलियन परिणाम है +सभी तुलना ऑपरेटर एक बूलियन मान लौटाते हैं: + +- सत्य - का अर्थ है "हाँ", "सही" या "सत्य"। +- असत्य - का अर्थ "नहीं", "गलत" या "सत्य नहीं" है। + +उदाहरण के लिए: + +alert( 2 > 1 ); // सच (सही) +alert( 2 == 1 ); // गलत (गलत) +alert( 2 != 1 ); // सच (सही) + + +एक तुलना परिणाम एक चर को सौंपा जा सकता है, किसी भी मूल्य की तरह: + +let result = 5 > 4; // तुलना का परिणाम बताएं +alert( result ); // सच + + +# स्ट्रिंग तुलना +यह देखने के लिए कि क्या एक स्ट्रिंग दूसरे से बड़ी है, जावास्क्रिप्ट तथाकथित "शब्दकोश" या "लेक्सिकोग्राफिक" आदेश का उपयोग करता है। + +दूसरे शब्दों में, स्ट्रिंग की तुलना अक्षर-दर-अक्षर की जाती है। + +उदाहरण के लिए: + +alert( 'Z' > 'A' ); // सच +alert( 'Glow' > 'Glee' ); // सच +alert( 'Bee' > 'Be' ); // सच + + +दो स्ट्रिंग की तुलना करने के लिए एल्गोरिथ्म सरल है: + +1.दोनों स्ट्रिंगों के पहले चरित्र की तुलना करें। +2.यदि पहली स्ट्रिंग से पहला वर्ण दूसरे स्ट्रिंग की तुलना में अधिक (या कम) है, तो पहली स्ट्रिंग दूसरी की तुलना में अधिक (या कम) है। हमारा काम हो गया। +3.अन्यथा, यदि दोनों तारों के पहले चरित्र समान हैं, तो दूसरे वर्णों की तुलना उसी तरह करें। +4.स्ट्रिंग के अंत तक यही दोहराएं। +5.यदि दोनों स्ट्रिंग एक ही लंबाई में समाप्त होते हैं, तो वे समान हैं। अन्यथायही , लंबी स्ट्रिंग अधिक होती है। From a42478021e6a65a9a1e9450a83e8f40b5b0772c7 Mon Sep 17 00:00:00 2001 From: Rishav Jadon Date: Fri, 2 Oct 2020 20:45:37 +0530 Subject: [PATCH 02/22] Update article1.md --- 1-js/02-first-steps/09-comparison/article1.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/1-js/02-first-steps/09-comparison/article1.md b/1-js/02-first-steps/09-comparison/article1.md index 201676866..035508007 100644 --- a/1-js/02-first-steps/09-comparison/article1.md +++ b/1-js/02-first-steps/09-comparison/article1.md @@ -19,17 +19,17 @@ - असत्य - का अर्थ "नहीं", "गलत" या "सत्य नहीं" है। उदाहरण के लिए: - +``` js run alert( 2 > 1 ); // सच (सही) alert( 2 == 1 ); // गलत (गलत) alert( 2 != 1 ); // सच (सही) - +``` एक तुलना परिणाम एक चर को सौंपा जा सकता है, किसी भी मूल्य की तरह: - +``` js run let result = 5 > 4; // तुलना का परिणाम बताएं alert( result ); // सच - +``` # स्ट्रिंग तुलना यह देखने के लिए कि क्या एक स्ट्रिंग दूसरे से बड़ी है, जावास्क्रिप्ट तथाकथित "शब्दकोश" या "लेक्सिकोग्राफिक" आदेश का उपयोग करता है। @@ -37,11 +37,11 @@ alert( result ); // सच दूसरे शब्दों में, स्ट्रिंग की तुलना अक्षर-दर-अक्षर की जाती है। उदाहरण के लिए: - +``` js run alert( 'Z' > 'A' ); // सच alert( 'Glow' > 'Glee' ); // सच alert( 'Bee' > 'Be' ); // सच - +``` दो स्ट्रिंग की तुलना करने के लिए एल्गोरिथ्म सरल है: From 840fea8d46e5d39f04e8920106332eb1665067af Mon Sep 17 00:00:00 2001 From: Rishav Jadon Date: Fri, 2 Oct 2020 20:50:26 +0530 Subject: [PATCH 03/22] Update article1.md --- 1-js/02-first-steps/09-comparison/article1.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/1-js/02-first-steps/09-comparison/article1.md b/1-js/02-first-steps/09-comparison/article1.md index 035508007..ed3c3522f 100644 --- a/1-js/02-first-steps/09-comparison/article1.md +++ b/1-js/02-first-steps/09-comparison/article1.md @@ -4,10 +4,10 @@ जावास्क्रिप्ट में वे इस तरह लिखे जाते हैं: -- ग्रेटर / से कम: ए> बी, ए <बी। -- ग्रेटर / से कम या बराबर: ए> = बी, ए <= बी। -- समतुल्य: a == b, कृपया दोहरे समानता चिन्ह पर ध्यान दें == का अर्थ है समानता परीक्षण, जबकि एकल a = b का अर्थ है असाइनमेंट। -- नहीं के बराबर है। गणित में अंकन ≠ है, लेकिन जावास्क्रिप्ट में इसे a =! B लिखा जाता है। +- ग्रेटर / से कम: a > b, a < b। +- ग्रेटर / से कम या बराबर: a >= b, a <= b। +- समतुल्य: `a == b`, कृपया दोहरे समानता चिन्ह पर ध्यान दें `==` का अर्थ है समानता परीक्षण, जबकि एकल `a = b` का अर्थ है असाइनमेंट। +- नहीं के बराबर है। गणित में अंकनहै, लेकिन जावास्क्रिप्ट में इसेa != b लिखा जाता है। इस लेख में हम विभिन्न प्रकार की तुलनाओं के बारे में अधिक जानेंगे, कि कैसे जावास्क्रिप्ट उन्हें महत्वपूर्ण विशिष्टता सहित बनाता है। अंत में आपको "जावास्क्रिप्ट क्विर्क" से संबंधित मुद्दों से बचने के लिए एक अच्छा नुस्खा मिलेगा। @@ -45,8 +45,8 @@ alert( 'Bee' > 'Be' ); // सच दो स्ट्रिंग की तुलना करने के लिए एल्गोरिथ्म सरल है: -1.दोनों स्ट्रिंगों के पहले चरित्र की तुलना करें। -2.यदि पहली स्ट्रिंग से पहला वर्ण दूसरे स्ट्रिंग की तुलना में अधिक (या कम) है, तो पहली स्ट्रिंग दूसरी की तुलना में अधिक (या कम) है। हमारा काम हो गया। -3.अन्यथा, यदि दोनों तारों के पहले चरित्र समान हैं, तो दूसरे वर्णों की तुलना उसी तरह करें। -4.स्ट्रिंग के अंत तक यही दोहराएं। -5.यदि दोनों स्ट्रिंग एक ही लंबाई में समाप्त होते हैं, तो वे समान हैं। अन्यथायही , लंबी स्ट्रिंग अधिक होती है। +1. दोनों स्ट्रिंगों के पहले चरित्र की तुलना करें। +2. यदि पहली स्ट्रिंग से पहला वर्ण दूसरे स्ट्रिंग की तुलना में अधिक (या कम) है, तो पहली स्ट्रिंग दूसरी की तुलना में अधिक (या कम) है। हमारा काम हो गया। +3. अन्यथा, यदि दोनों तारों के पहले चरित्र समान हैं, तो दूसरे वर्णों की तुलना उसी तरह करें। +4. स्ट्रिंग के अंत तक यही दोहराएं। +5. यदि दोनों स्ट्रिंग एक ही लंबाई में समाप्त होते हैं, तो वे समान हैं। अन्यथायही , लंबी स्ट्रिंग अधिक होती है। From a42dda5ad7fc1033b70f785e85db49264204e120 Mon Sep 17 00:00:00 2001 From: Rishav Jadon Date: Fri, 2 Oct 2020 20:58:24 +0530 Subject: [PATCH 04/22] Update article1.md --- 1-js/02-first-steps/09-comparison/article1.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/1-js/02-first-steps/09-comparison/article1.md b/1-js/02-first-steps/09-comparison/article1.md index ed3c3522f..09ec80ec3 100644 --- a/1-js/02-first-steps/09-comparison/article1.md +++ b/1-js/02-first-steps/09-comparison/article1.md @@ -50,3 +50,18 @@ alert( 'Bee' > 'Be' ); // सच 3. अन्यथा, यदि दोनों तारों के पहले चरित्र समान हैं, तो दूसरे वर्णों की तुलना उसी तरह करें। 4. स्ट्रिंग के अंत तक यही दोहराएं। 5. यदि दोनों स्ट्रिंग एक ही लंबाई में समाप्त होते हैं, तो वे समान हैं। अन्यथायही , लंबी स्ट्रिंग अधिक होती है। + +ऊपर दिए गए उदाहरणों में, `'Z'> 'A'` की तुलना पहले चरण में होती है जबकि `"Glow"` और `"Glee"` वर्ण-दर-वर्ण की तुलना की जाती है: + +1. `G`, `G` के समान है। +2. `l`, `l` के समान है। +3. `o`, `e` से बड़ा है। यहाँ रुको। पहली स्ट्रिंग अधिक होती है। + +```smart header="Not a real dictionary, but Unicode order" +ऊपर दिए गए तुलना एल्गोरिथ्म लगभग शब्दकोशों या फोन पुस्तकों में उपयोग किए जाने वाले के बराबर है, लेकिन यह बिल्कुल समान नहीं है। + +मसलन, मामला मायने रखता है। एक कैपिटल लेटर `'A'` लोअरकेस `'a' 'के बराबर नहीं है। कौन सा अधिक है? लोअरकेस `'a'`। क्यों? क्योंकि आंतरिक एन्कोडिंग तालिका जावास्क्रिप्ट उपयोग (यूनिकोड) में लोअरकेस वर्ण का एक बड़ा सूचकांक है। हम अध्याय में इसके विशिष्ट विवरण और परिणाम प्राप्त करेंगे। +``` + +# विभिन्न प्रकारों की तुलना +विभिन्न प्रकारों के मूल्यों की तुलना करते समय, जावास्क्रिप्ट मानों को संख्याओं में परिवर्तित करता है। From 535f742f8134df802c332df3fc03ce4174b76c26 Mon Sep 17 00:00:00 2001 From: Rishav Jadon Date: Fri, 2 Oct 2020 21:08:48 +0530 Subject: [PATCH 05/22] Update article1.md --- 1-js/02-first-steps/09-comparison/article1.md | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/1-js/02-first-steps/09-comparison/article1.md b/1-js/02-first-steps/09-comparison/article1.md index 09ec80ec3..6ff057e73 100644 --- a/1-js/02-first-steps/09-comparison/article1.md +++ b/1-js/02-first-steps/09-comparison/article1.md @@ -65,3 +65,37 @@ alert( 'Bee' > 'Be' ); // सच # विभिन्न प्रकारों की तुलना विभिन्न प्रकारों के मूल्यों की तुलना करते समय, जावास्क्रिप्ट मानों को संख्याओं में परिवर्तित करता है। +उदाहरण के लिए: +``` js run +alert( '2' > 1 ); // सच, स्ट्रिंग '2' नंबर 2 बन जाता है +alert('01' == 1); // सच, स्ट्रिंग '01' नंबर 1 बन जाता है +``` +बूलियन मूल्यों के लिए, सत्य 1 हो जाता है और असत्य 0 हो जाता है। + +उदाहरण के लिए: +``` js run +सतर्क (सही == 1); // सच +चेतावनी (गलत == 0); // सच +``` +````smart header="A funny consequence" +यह संभव है, कि एक ही समय में: + +- दो मूल्य समान हैं। +- उनमें से एक `सच` एक बूलियन के रूप में है और दूसरा एक `गलत` बूलियन के रूप में है। + +उदाहरण के लिए: + +```js run +let a = 0; +alert( Boolean(a) ); // असत्य + +let b = "0"; +alert( Boolean(a) ); // सच + +alert(a == b); // सच! +``` + +जावास्क्रिप्ट के दृष्टिकोण से, यह परिणाम काफी सामान्य है। एक समानता जांच संख्यात्मक रूपांतरण का उपयोग करके मूल्यों को परिवर्तित करता है (इसलिए `"0"`, `0` बन जाता है), जबकि स्पष्ट `बुलियन` रूपांतरण नियमों के एक और सेट का उपयोग करता है। +```` + +# सख्त समानता From 21da1f53f5ec163c09ec945f831574a720ce5b83 Mon Sep 17 00:00:00 2001 From: Rishav Jadon Date: Fri, 2 Oct 2020 21:22:03 +0530 Subject: [PATCH 06/22] Update article1.md --- 1-js/02-first-steps/09-comparison/article1.md | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/1-js/02-first-steps/09-comparison/article1.md b/1-js/02-first-steps/09-comparison/article1.md index 6ff057e73..908a14cf7 100644 --- a/1-js/02-first-steps/09-comparison/article1.md +++ b/1-js/02-first-steps/09-comparison/article1.md @@ -99,3 +99,46 @@ alert(a == b); // सच! ```` # सख्त समानता + +एक नियमित समानता की जांच `==`में एक समस्या है। यह `0` को गलत से अलग नहीं कर सकता: +```js run +alert( 0 == false ); // सच +``` +खाली स्ट्रिंग के साथ भी यही होता है: +``` js run +alert('' == false); // सच +``` +ऐसा इसलिए होता है क्योंकि विभिन्न प्रकार के ऑपरेंड को समानता ऑपरेटर == द्वारा संख्याओं में परिवर्तित किया जाता है। खाली स्ट्रिंग, झूठ की तरह, एक शून्य बन जाती है। + +अगर हम असत्य से `0` को अलग करना चाहते हैं तो क्या करें? + +**एक सख्त समानता ऑपरेटर `===` बिना रूपांतरण के समानता की जांच करता है।** + +दूसरे शब्दों में, यदि `a` और `b` अलग-अलग प्रकार के हैं, तो `a === b` तुरंत उन्हें बदलने के प्रयास के बिना झूठा लौट आता है। + +चलो यह कोशिश करते हैं: +```js run +alert( 0 === false); // असत्य, क्योंकि प्रकार भिन्न हैं +``` + +एक "सख्त गैर-समानता" ऑपरेटर भी है `!==` के अनुरूप है `! =`। + +सख्त समानता ऑपरेटर लिखने के लिए थोड़ा लंबा है, लेकिन यह स्पष्ट करता है कि क्या चल रहा है और त्रुटियों के लिए कम जगह छोड़ता है। + +# अशक्त और अपरिभाषित के साथ तुलना +अन्य मानों की तुलना में अशक्त या अपरिभाषित होने पर एक गैर-सहज व्यवहार होता है। + +सख्त समानता की जांच के लिए ===: ये मूल्य अलग-अलग हैं, क्योंकि उनमें से प्रत्येक एक अलग प्रकार है। + +```js run +चेतावनी (अशक्त === अपरिभाषित); // असत्य +``` + +गैर-सख्त चेक के लिए ==: एक विशेष नियम है। ये दोनों एक "स्वीट कपल" हैं: वे एक-दूसरे के बराबर (== के अर्थ में) हैं, लेकिन कोई दूसरा मूल्य नहीं। + +`` `जे एस भागो +चेतावनी (अशक्त == अपरिभाषित); // सच +`` ` +गणित और अन्य तुलनाओं के लिए <> <=> =: अशक्त / अपरिभाषित संख्या में परिवर्तित हो जाते हैं: अशक्त 0 हो जाता है, जबकि अपरिभाषित NaN हो जाता है। + +अब देखते हैं कुछ मजेदार बातें जो हम इन नियमों को लागू करते हैं। और, क्या अधिक महत्वपूर्ण है, कैसे उनके साथ एक जाल में नहीं पड़ना। From 637296183e68229fbfc14079d41ca14b7ad02d03 Mon Sep 17 00:00:00 2001 From: Rishav Jadon Date: Fri, 2 Oct 2020 23:07:47 +0530 Subject: [PATCH 07/22] Update article1.md --- 1-js/02-first-steps/09-comparison/article1.md | 71 +++++++++++++++---- 1 file changed, 59 insertions(+), 12 deletions(-) diff --git a/1-js/02-first-steps/09-comparison/article1.md b/1-js/02-first-steps/09-comparison/article1.md index 908a14cf7..9290d1472 100644 --- a/1-js/02-first-steps/09-comparison/article1.md +++ b/1-js/02-first-steps/09-comparison/article1.md @@ -74,9 +74,10 @@ alert('01' == 1); // सच, स्ट्रिंग '01' नंबर 1 बन उदाहरण के लिए: ``` js run -सतर्क (सही == 1); // सच -चेतावनी (गलत == 0); // सच +alert ( true == 1 ); // सच +alert ( false == 0 ); // सच ``` + ````smart header="A funny consequence" यह संभव है, कि एक ही समय में: @@ -125,20 +126,66 @@ alert( 0 === false); // असत्य, क्योंकि प्रका सख्त समानता ऑपरेटर लिखने के लिए थोड़ा लंबा है, लेकिन यह स्पष्ट करता है कि क्या चल रहा है और त्रुटियों के लिए कम जगह छोड़ता है। -# अशक्त और अपरिभाषित के साथ तुलना -अन्य मानों की तुलना में अशक्त या अपरिभाषित होने पर एक गैर-सहज व्यवहार होता है। +# नल और ुन्डेफिनेड के साथ तुलना +अन्य मानों की तुलना में नल या ुन्डेफिनेड होने पर एक गैर-सहज व्यवहार होता है। + +सख्त समानता की जांच के लिए `===` +: ये मूल्य अलग-अलग हैं, क्योंकि उनमें से प्रत्येक एक अलग प्रकार है। + +```js run +alert( null === undefined ); // असत्य +``` + +गैर-सख्त चेक के लिए `==` +: एक विशेष नियम है। ये दोनों एक "स्वीट कपल" हैं: वे एक-दूसरे के बराबर (`==` के अर्थ में) हैं, लेकिन कोई दूसरा मूल्य नहीं। + +```js run +alert( null == undefined ); // सच +``` + +गणित और अन्य तुलनाओं के लिए `<> <=> =` +: नल / ुन्डेफिनेड संख्या में परिवर्तित हो जाते हैं: `null` 0 हो जाता है, जबकि `undefined` `NaN` हो जाता है। -सख्त समानता की जांच के लिए ===: ये मूल्य अलग-अलग हैं, क्योंकि उनमें से प्रत्येक एक अलग प्रकार है। +अब देखते हैं कुछ मजेदार चीजें, जो तब होती हैं, जब हम इन नियमों को लागू करते हैं। और, क्या अधिक महत्वपूर्ण है, कैसे उनके साथ एक जाल में नहीं पड़ना। +# अजीब परिणाम: नल बनाम 0 +चलो `null` के साथ `0` की तुलना करें: ```js run -चेतावनी (अशक्त === अपरिभाषित); // असत्य +alert( null > 0); // (1) झूठा +alert( null == 0); // (2) झूठा +alert( null >= 0); // (3) *! * सच * /! * ``` -गैर-सख्त चेक के लिए ==: एक विशेष नियम है। ये दोनों एक "स्वीट कपल" हैं: वे एक-दूसरे के बराबर (== के अर्थ में) हैं, लेकिन कोई दूसरा मूल्य नहीं। +गणितीय, यह अजीब है। अंतिम परिणाम में कहा गया है कि "`null` शून्य से अधिक या शून्य के बराबर है", इसलिए ऊपर की तुलनाओं में से एक में यह सच होना चाहिए, लेकिन वे दोनों झूठे हैं। + +कारण यह है कि एक समानता जांच `==` और तुलना `> <> = <=` अलग तरीके से काम करते हैं। तुलना शून्य को एक संख्या में बदल देती है, इसे `0` मानते हैं। इसीलिए (3) `null> = 0` सत्य है और (1) `null> 0` मिथ्या है। + +दूसरी ओर, `null` और `undefined` के लिए समानता की जांच `==` को ऐसे परिभाषित किया गया है, बिना किसी रूपांतरण के, वे एक-दूसरे के बराबर हैं और किसी अन्य चीज़ के बराबर नहीं हैं। इसीलिए (2) `null == 0` असत्य है। + +# एक अतुलनीय ुन्डेफिनेड + ुन्डेफिनेड मूल्य को अन्य मूल्यों की तुलना में नहीं किया जाना चाहिए: +```js run +alert( undefined > 0); // झूठा (1) +alert( undefined < 0); // झूठा (2) +alert( undefined == 0); // झूठा (3) +``` + +यह शून्य को इतना नापसंद क्यों करता है? हमेशा झूठा! + +हमें ये परिणाम मिले क्योंकि: + +- तुलना (1) और (2) झूठी हो जाती है क्योंकि अपरिभाषित NaN में परिवर्तित हो जाता है और NaN एक विशेष संख्यात्मक मान होता है जो सभी तुलनाओं के लिए गलत होता है। +- समानता की जांच (3) झूठी होती है क्योंकि अपरिभाषित केवल अशक्त, अपरिभाषित और कोई अन्य मूल्य नहीं के बराबर होता है। + +# समस्याओं से बचें +हम इन उदाहरणों पर क्यों गए? क्या हमें हर समय इन ख़ासियतों को याद रखना चाहिए? असल में ऐसा नहीं है। दरअसल, ये मुश्किल चीजें धीरे-धीरे समय के साथ परिचित हो जाएंगी, लेकिन उनके साथ समस्याओं से बचने का एक ठोस तरीका है: -`` `जे एस भागो -चेतावनी (अशक्त == अपरिभाषित); // सच -`` ` -गणित और अन्य तुलनाओं के लिए <> <=> =: अशक्त / अपरिभाषित संख्या में परिवर्तित हो जाते हैं: अशक्त 0 हो जाता है, जबकि अपरिभाषित NaN हो जाता है। +- असाधारण देखभाल के साथ सख्त समानता === को छोड़कर अपरिभाषित / अशक्त के साथ किसी भी तुलना का व्यवहार करें। +- तुलना का उपयोग न करें> => <<= एक चर के साथ जो अशक्त / अपरिभाषित हो सकता है, जब तक कि आप वास्तव में निश्चित नहीं हैं कि आप क्या कर रहे हैं। यदि किसी चर में ये मान हो सकते हैं, तो उनके लिए अलग से जाँच करें। -अब देखते हैं कुछ मजेदार बातें जो हम इन नियमों को लागू करते हैं। और, क्या अधिक महत्वपूर्ण है, कैसे उनके साथ एक जाल में नहीं पड़ना। +# सारांश +- तुलना ऑपरेटर एक बूलियन मान लौटाते हैं। +- स्ट्रिंग्स की तुलना "शब्दकोश" क्रम में अक्षर-दर-अक्षर से की जाती है। +- जब विभिन्न प्रकारों के मूल्यों की तुलना की जाती है, तो वे संख्याओं में परिवर्तित हो जाते हैं (एक सख्त समानता जांच के बहिष्करण के साथ)। +- मान शून्य और अपरिभाषित समान == एक दूसरे को और किसी भी अन्य मूल्य के बराबर नहीं है। +- वैरिएबल के साथ> या <जैसे तुलनाओं का उपयोग करते समय सावधान रहें जो कभी-कभी अशक्त / अपरिभाषित हो सकते हैं। अशक्त / अपरिभाषित के लिए अलग से जाँच करना एक अच्छा विचार है। From 1e6e281d36fe36299a883da5e747a57a865e58c3 Mon Sep 17 00:00:00 2001 From: Rishav Jadon Date: Fri, 2 Oct 2020 23:50:33 +0530 Subject: [PATCH 08/22] Update article1.md --- 1-js/02-first-steps/09-comparison/article1.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/1-js/02-first-steps/09-comparison/article1.md b/1-js/02-first-steps/09-comparison/article1.md index 9290d1472..e3bc3f0ef 100644 --- a/1-js/02-first-steps/09-comparison/article1.md +++ b/1-js/02-first-steps/09-comparison/article1.md @@ -174,18 +174,18 @@ alert( undefined == 0); // झूठा (3) हमें ये परिणाम मिले क्योंकि: -- तुलना (1) और (2) झूठी हो जाती है क्योंकि अपरिभाषित NaN में परिवर्तित हो जाता है और NaN एक विशेष संख्यात्मक मान होता है जो सभी तुलनाओं के लिए गलत होता है। -- समानता की जांच (3) झूठी होती है क्योंकि अपरिभाषित केवल अशक्त, अपरिभाषित और कोई अन्य मूल्य नहीं के बराबर होता है। +- तुलना (1) और (2) झूठी हो जाती है क्योंकि `undefined` `NaN` में परिवर्तित हो जाता है और `NaN` एक विशेष संख्यात्मक मान होता है जो सभी तुलनाओं के लिए गलत होता है। +- समानता की जांच (3) झूठी होती है क्योंकि `undefined` केवल `null` और `undefined` के बराबर होता है। # समस्याओं से बचें हम इन उदाहरणों पर क्यों गए? क्या हमें हर समय इन ख़ासियतों को याद रखना चाहिए? असल में ऐसा नहीं है। दरअसल, ये मुश्किल चीजें धीरे-धीरे समय के साथ परिचित हो जाएंगी, लेकिन उनके साथ समस्याओं से बचने का एक ठोस तरीका है: -- असाधारण देखभाल के साथ सख्त समानता === को छोड़कर अपरिभाषित / अशक्त के साथ किसी भी तुलना का व्यवहार करें। -- तुलना का उपयोग न करें> => <<= एक चर के साथ जो अशक्त / अपरिभाषित हो सकता है, जब तक कि आप वास्तव में निश्चित नहीं हैं कि आप क्या कर रहे हैं। यदि किसी चर में ये मान हो सकते हैं, तो उनके लिए अलग से जाँच करें। +- असाधारण देखभाल के साथ सख्त समानता `===` को छोड़कर `undefined/null` के साथ किसी भी तुलना का व्यवहार करें। +- तुलना का उपयोग न करें `> => <<=` एक वेरिएबल के साथ जो `undefined/null` हो सकता है, जब तक कि आप वास्तव में निश्चित नहीं हैं कि आप क्या कर रहे हैं। यदि किसी वेरिएबल में ये मान हो सकते हैं, तो उनके लिए अलग से जाँच करें। # सारांश - तुलना ऑपरेटर एक बूलियन मान लौटाते हैं। - स्ट्रिंग्स की तुलना "शब्दकोश" क्रम में अक्षर-दर-अक्षर से की जाती है। - जब विभिन्न प्रकारों के मूल्यों की तुलना की जाती है, तो वे संख्याओं में परिवर्तित हो जाते हैं (एक सख्त समानता जांच के बहिष्करण के साथ)। -- मान शून्य और अपरिभाषित समान == एक दूसरे को और किसी भी अन्य मूल्य के बराबर नहीं है। -- वैरिएबल के साथ> या <जैसे तुलनाओं का उपयोग करते समय सावधान रहें जो कभी-कभी अशक्त / अपरिभाषित हो सकते हैं। अशक्त / अपरिभाषित के लिए अलग से जाँच करना एक अच्छा विचार है। +- मान, `null`और `undefined` समान `==` एक दूसरे के, और किसी भी अन्य मूल्य के बराबर नहीं है। +- वैरिएबल के साथ `>` या `<` जैसे तुलनाओं का उपयोग करते समय सावधान रहें जो कभी-कभी `undefined/null` हो सकते हैं। `undefined/null` के लिए अलग से जाँच करना एक अच्छा विचार है। From 239262e8683e610501ad9dd0fd4d4f28333fc719 Mon Sep 17 00:00:00 2001 From: Rishav Jadon Date: Fri, 2 Oct 2020 23:53:59 +0530 Subject: [PATCH 09/22] Create task1.md --- .../02-first-steps/09-comparison/1-comparison-questions/task1.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 1-js/02-first-steps/09-comparison/1-comparison-questions/task1.md diff --git a/1-js/02-first-steps/09-comparison/1-comparison-questions/task1.md b/1-js/02-first-steps/09-comparison/1-comparison-questions/task1.md new file mode 100644 index 000000000..72acb08a8 --- /dev/null +++ b/1-js/02-first-steps/09-comparison/1-comparison-questions/task1.md @@ -0,0 +1 @@ +इन भावों का परिणाम क्या होगा? From be2f9638be8eb42cd74d3f59a84040f89899cc77 Mon Sep 17 00:00:00 2001 From: Rishav Jadon Date: Fri, 2 Oct 2020 23:55:38 +0530 Subject: [PATCH 10/22] Update task1.md --- .../1-comparison-questions/task1.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/1-js/02-first-steps/09-comparison/1-comparison-questions/task1.md b/1-js/02-first-steps/09-comparison/1-comparison-questions/task1.md index 72acb08a8..a2f9fa3d7 100644 --- a/1-js/02-first-steps/09-comparison/1-comparison-questions/task1.md +++ b/1-js/02-first-steps/09-comparison/1-comparison-questions/task1.md @@ -1 +1,19 @@ +importance: 5 + +--- + +# तुलना + इन भावों का परिणाम क्या होगा? + +```js no-beautify +5 > 4 +"apple" > "pineapple" +"2" > "12" +undefined == null +undefined === null +null == "\n0\n" +null === +"\n0\n" +``` + + From 3dac383a853e627e6d36c7210947c0d60d85322d Mon Sep 17 00:00:00 2001 From: Rishav Jadon Date: Fri, 2 Oct 2020 23:59:11 +0530 Subject: [PATCH 11/22] Create solution1.md --- .../1-comparison-questions/solution1.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 1-js/02-first-steps/09-comparison/1-comparison-questions/solution1.md diff --git a/1-js/02-first-steps/09-comparison/1-comparison-questions/solution1.md b/1-js/02-first-steps/09-comparison/1-comparison-questions/solution1.md new file mode 100644 index 000000000..74b10a2df --- /dev/null +++ b/1-js/02-first-steps/09-comparison/1-comparison-questions/solution1.md @@ -0,0 +1,19 @@ + +```js no-beautify +5 > 4 → true +"apple" > "pineapple" → false +"2" > "12" → true +undefined == null → true +undefined === null → false +null == "\n0\n" → false +null === +"\n0\n" → false +``` +कारणों में से कुछ: + +1. जाहिर है, सच है। +2. शब्दकोश की तुलना, इसलिए झूठी है। `" a "` `"p"` से छोटा है। +3. फिर से, शब्दकोश तुलना, `" 2 "का पहला चार्ट` `1" के पहले चार्ट से अधिक है। +4. मान `null` और `undefined` एक-दूसरे के बराबर हैं। +5. सख्त समानता सख्त है। दोनों तरफ से अलग-अलग प्रकार झूठे होते हैं। +6. `(4)` के समान, `null` केवल `undefined` के बराबर है। +7. विभिन्न प्रकार की सख्त समानता। From f9cabce54bf3b982a47f87e4439f41c2b2a80295 Mon Sep 17 00:00:00 2001 From: Rishav Jadon Date: Sat, 3 Oct 2020 00:02:24 +0530 Subject: [PATCH 12/22] Update solution1.md --- .../09-comparison/1-comparison-questions/solution1.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/1-js/02-first-steps/09-comparison/1-comparison-questions/solution1.md b/1-js/02-first-steps/09-comparison/1-comparison-questions/solution1.md index 74b10a2df..7b7cc3dfa 100644 --- a/1-js/02-first-steps/09-comparison/1-comparison-questions/solution1.md +++ b/1-js/02-first-steps/09-comparison/1-comparison-questions/solution1.md @@ -11,8 +11,8 @@ null === +"\n0\n" → false कारणों में से कुछ: 1. जाहिर है, सच है। -2. शब्दकोश की तुलना, इसलिए झूठी है। `" a "` `"p"` से छोटा है। -3. फिर से, शब्दकोश तुलना, `" 2 "का पहला चार्ट` `1" के पहले चार्ट से अधिक है। +2. शब्दकोश की तुलना, इसलिए झूठी है। `"a"` `"p"` से छोटा है। +3. फिर से, शब्दकोश तुलना, `"2"` का पहला करैक्टर` `"1"` के पहले करैक्टर से अधिक है। 4. मान `null` और `undefined` एक-दूसरे के बराबर हैं। 5. सख्त समानता सख्त है। दोनों तरफ से अलग-अलग प्रकार झूठे होते हैं। 6. `(4)` के समान, `null` केवल `undefined` के बराबर है। From 7d1a594e4b6afeda7fd59787f91b9695bebeda2a Mon Sep 17 00:00:00 2001 From: Rishav Jadon Date: Sat, 3 Oct 2020 00:03:19 +0530 Subject: [PATCH 13/22] Update solution1.md --- .../09-comparison/1-comparison-questions/solution1.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/02-first-steps/09-comparison/1-comparison-questions/solution1.md b/1-js/02-first-steps/09-comparison/1-comparison-questions/solution1.md index 7b7cc3dfa..5b3aefba7 100644 --- a/1-js/02-first-steps/09-comparison/1-comparison-questions/solution1.md +++ b/1-js/02-first-steps/09-comparison/1-comparison-questions/solution1.md @@ -8,7 +8,7 @@ undefined === null → false null == "\n0\n" → false null === +"\n0\n" → false ``` -कारणों में से कुछ: +कुछ कारण: 1. जाहिर है, सच है। 2. शब्दकोश की तुलना, इसलिए झूठी है। `"a"` `"p"` से छोटा है। From fe27b746590ea22d12a228a61fb0b332706b5dd4 Mon Sep 17 00:00:00 2001 From: Rishav Jadon Date: Sat, 3 Oct 2020 00:04:13 +0530 Subject: [PATCH 14/22] Update solution1.md --- .../09-comparison/1-comparison-questions/solution1.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/02-first-steps/09-comparison/1-comparison-questions/solution1.md b/1-js/02-first-steps/09-comparison/1-comparison-questions/solution1.md index 5b3aefba7..44cf65d15 100644 --- a/1-js/02-first-steps/09-comparison/1-comparison-questions/solution1.md +++ b/1-js/02-first-steps/09-comparison/1-comparison-questions/solution1.md @@ -12,7 +12,7 @@ null === +"\n0\n" → false 1. जाहिर है, सच है। 2. शब्दकोश की तुलना, इसलिए झूठी है। `"a"` `"p"` से छोटा है। -3. फिर से, शब्दकोश तुलना, `"2"` का पहला करैक्टर` `"1"` के पहले करैक्टर से अधिक है। +3. फिर से, शब्दकोश तुलना, `"2"` का पहला करैक्टर `"1"` के पहले करैक्टर से अधिक है। 4. मान `null` और `undefined` एक-दूसरे के बराबर हैं। 5. सख्त समानता सख्त है। दोनों तरफ से अलग-अलग प्रकार झूठे होते हैं। 6. `(4)` के समान, `null` केवल `undefined` के बराबर है। From 96b22ca33e27db86952009baafffbae389608983 Mon Sep 17 00:00:00 2001 From: Rishav Jadon Date: Sat, 3 Oct 2020 00:04:54 +0530 Subject: [PATCH 15/22] Delete solution.md --- .../1-comparison-questions/solution.md | 21 ------------------- 1 file changed, 21 deletions(-) delete mode 100644 1-js/02-first-steps/09-comparison/1-comparison-questions/solution.md diff --git a/1-js/02-first-steps/09-comparison/1-comparison-questions/solution.md b/1-js/02-first-steps/09-comparison/1-comparison-questions/solution.md deleted file mode 100644 index a86a9f73e..000000000 --- a/1-js/02-first-steps/09-comparison/1-comparison-questions/solution.md +++ /dev/null @@ -1,21 +0,0 @@ - - -```js no-beautify -5 > 4 → true -"apple" > "pineapple" → false -"2" > "12" → true -undefined == null → true -undefined === null → false -null == "\n0\n" → false -null === +"\n0\n" → false -``` - -Some of the reasons: - -1. Obviously, true. -2. Dictionary comparison, hence false. `"a"` is smaller than `"p"`. -3. Again, dictionary comparison, first char of `"2"` is greater than the first char of `"1"`. -4. Values `null` and `undefined` equal each other only. -5. Strict equality is strict. Different types from both sides lead to false. -6. Similar to `(4)`, `null` only equals `undefined`. -7. Strict equality of different types. From 6c704fd080b26e270cb1ed8f610733e47b8ef1ec Mon Sep 17 00:00:00 2001 From: Rishav Jadon Date: Sat, 3 Oct 2020 00:05:08 +0530 Subject: [PATCH 16/22] Delete task.md --- .../1-comparison-questions/task.md | 18 ------------------ 1 file changed, 18 deletions(-) delete mode 100644 1-js/02-first-steps/09-comparison/1-comparison-questions/task.md diff --git a/1-js/02-first-steps/09-comparison/1-comparison-questions/task.md b/1-js/02-first-steps/09-comparison/1-comparison-questions/task.md deleted file mode 100644 index be7f75ddd..000000000 --- a/1-js/02-first-steps/09-comparison/1-comparison-questions/task.md +++ /dev/null @@ -1,18 +0,0 @@ -importance: 5 - ---- - -# Comparisons - -What will be the result for these expressions? - -```js no-beautify -5 > 4 -"apple" > "pineapple" -"2" > "12" -undefined == null -undefined === null -null == "\n0\n" -null === +"\n0\n" -``` - From 77b6cfd53c216a072bf449612c8acfbf5d966e03 Mon Sep 17 00:00:00 2001 From: Rishav Jadon Date: Sat, 3 Oct 2020 00:05:26 +0530 Subject: [PATCH 17/22] Rename solution1.md to solution.md --- .../1-comparison-questions/{solution1.md => solution.md} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename 1-js/02-first-steps/09-comparison/1-comparison-questions/{solution1.md => solution.md} (100%) diff --git a/1-js/02-first-steps/09-comparison/1-comparison-questions/solution1.md b/1-js/02-first-steps/09-comparison/1-comparison-questions/solution.md similarity index 100% rename from 1-js/02-first-steps/09-comparison/1-comparison-questions/solution1.md rename to 1-js/02-first-steps/09-comparison/1-comparison-questions/solution.md From c4de812ec1e5b1f0e17604317c4c0b4f8b2de2ac Mon Sep 17 00:00:00 2001 From: Rishav Jadon Date: Sat, 3 Oct 2020 00:05:52 +0530 Subject: [PATCH 18/22] Rename task1.md to task.md --- .../09-comparison/1-comparison-questions/{task1.md => task.md} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename 1-js/02-first-steps/09-comparison/1-comparison-questions/{task1.md => task.md} (100%) diff --git a/1-js/02-first-steps/09-comparison/1-comparison-questions/task1.md b/1-js/02-first-steps/09-comparison/1-comparison-questions/task.md similarity index 100% rename from 1-js/02-first-steps/09-comparison/1-comparison-questions/task1.md rename to 1-js/02-first-steps/09-comparison/1-comparison-questions/task.md From c537c544f7918d68fd8f660d53fe20dae5990543 Mon Sep 17 00:00:00 2001 From: Rishav Jadon Date: Sat, 3 Oct 2020 00:06:12 +0530 Subject: [PATCH 19/22] Delete article.md --- 1-js/02-first-steps/09-comparison/article.md | 214 ------------------- 1 file changed, 214 deletions(-) delete mode 100644 1-js/02-first-steps/09-comparison/article.md diff --git a/1-js/02-first-steps/09-comparison/article.md b/1-js/02-first-steps/09-comparison/article.md deleted file mode 100644 index a323dc93d..000000000 --- a/1-js/02-first-steps/09-comparison/article.md +++ /dev/null @@ -1,214 +0,0 @@ -# Comparisons - -We know many comparison operators from maths. - -In JavaScript they are written like this: - -- Greater/less than: a > b, a < b. -- Greater/less than or equals: a >= b, a <= b. -- Equals: `a == b`, please note the double equality sign `==` means the equality test, while a single one `a = b` means an assignment. -- Not equals. In maths the notation is , but in JavaScript it's written as a != b. - -In this article we'll learn more about different types of comparisons, how JavaScript makes them, including important peculiarities. - -At the end you'll find a good recipe to avoid "javascript quirks"-related issues. - -## Boolean is the result - -All comparison operators return a boolean value: - -- `true` -- means "yes", "correct" or "the truth". -- `false` -- means "no", "wrong" or "not the truth". - -For example: - -```js run -alert( 2 > 1 ); // true (correct) -alert( 2 == 1 ); // false (wrong) -alert( 2 != 1 ); // true (correct) -``` - -A comparison result can be assigned to a variable, just like any value: - -```js run -let result = 5 > 4; // assign the result of the comparison -alert( result ); // true -``` - -## String comparison - -To see whether a string is greater than another, JavaScript uses the so-called "dictionary" or "lexicographical" order. - -In other words, strings are compared letter-by-letter. - -For example: - -```js run -alert( 'Z' > 'A' ); // true -alert( 'Glow' > 'Glee' ); // true -alert( 'Bee' > 'Be' ); // true -``` - -The algorithm to compare two strings is simple: - -1. Compare the first character of both strings. -2. If the first character from the first string is greater (or less) than the other string's, then the first string is greater (or less) than the second. We're done. -3. Otherwise, if both strings' first characters are the same, compare the second characters the same way. -4. Repeat until the end of either string. -5. If both strings end at the same length, then they are equal. Otherwise, the longer string is greater. - -In the examples above, the comparison `'Z' > 'A'` gets to a result at the first step while the strings `"Glow"` and `"Glee"` are compared character-by-character: - -1. `G` is the same as `G`. -2. `l` is the same as `l`. -3. `o` is greater than `e`. Stop here. The first string is greater. - -```smart header="Not a real dictionary, but Unicode order" -The comparison algorithm given above is roughly equivalent to the one used in dictionaries or phone books, but it's not exactly the same. - -For instance, case matters. A capital letter `"A"` is not equal to the lowercase `"a"`. Which one is greater? The lowercase `"a"`. Why? Because the lowercase character has a greater index in the internal encoding table JavaScript uses (Unicode). We'll get back to specific details and consequences of this in the chapter . -``` - -## Comparison of different types - -When comparing values of different types, JavaScript converts the values to numbers. - -For example: - -```js run -alert( '2' > 1 ); // true, string '2' becomes a number 2 -alert( '01' == 1 ); // true, string '01' becomes a number 1 -``` - -For boolean values, `true` becomes `1` and `false` becomes `0`. - -For example: - -```js run -alert( true == 1 ); // true -alert( false == 0 ); // true -``` - -````smart header="A funny consequence" -It is possible that at the same time: - -- Two values are equal. -- One of them is `true` as a boolean and the other one is `false` as a boolean. - -For example: - -```js run -let a = 0; -alert( Boolean(a) ); // false - -let b = "0"; -alert( Boolean(b) ); // true - -alert(a == b); // true! -``` - -From JavaScript's standpoint, this result is quite normal. An equality check converts values using the numeric conversion (hence `"0"` becomes `0`), while the explicit `Boolean` conversion uses another set of rules. -```` - -## Strict equality - -A regular equality check `==` has a problem. It cannot differentiate `0` from `false`: - -```js run -alert( 0 == false ); // true -``` - -The same thing happens with an empty string: - -```js run -alert( '' == false ); // true -``` - -This happens because operands of different types are converted to numbers by the equality operator `==`. An empty string, just like `false`, becomes a zero. - -What to do if we'd like to differentiate `0` from `false`? - -**A strict equality operator `===` checks the equality without type conversion.** - -In other words, if `a` and `b` are of different types, then `a === b` immediately returns `false` without an attempt to convert them. - -Let's try it: - -```js run -alert( 0 === false ); // false, because the types are different -``` - -There is also a "strict non-equality" operator `!==` analogous to `!=`. - -The strict equality operator is a bit longer to write, but makes it obvious what's going on and leaves less room for errors. - -## Comparison with null and undefined - -There's a non-intuitive behavior when `null` or `undefined` are compared to other values. - -For a strict equality check `===` -: These values are different, because each of them is a different type. - - ```js run - alert( null === undefined ); // false - ``` - -For a non-strict check `==` -: There's a special rule. These two are a "sweet couple": they equal each other (in the sense of `==`), but not any other value. - - ```js run - alert( null == undefined ); // true - ``` - -For maths and other comparisons `< > <= >=` -: `null/undefined` are converted to numbers: `null` becomes `0`, while `undefined` becomes `NaN`. - -Now let's see some funny things that happen when we apply these rules. And, what's more important, how to not fall into a trap with them. - -### Strange result: null vs 0 - -Let's compare `null` with a zero: - -```js run -alert( null > 0 ); // (1) false -alert( null == 0 ); // (2) false -alert( null >= 0 ); // (3) *!*true*/!* -``` - -Mathematically, that's strange. The last result states that "`null` is greater than or equal to zero", so in one of the comparisons above it must be `true`, but they are both false. - -The reason is that an equality check `==` and comparisons `> < >= <=` work differently. Comparisons convert `null` to a number, treating it as `0`. That's why (3) `null >= 0` is true and (1) `null > 0` is false. - -On the other hand, the equality check `==` for `undefined` and `null` is defined such that, without any conversions, they equal each other and don't equal anything else. That's why (2) `null == 0` is false. - -### An incomparable undefined - -The value `undefined` shouldn't be compared to other values: - -```js run -alert( undefined > 0 ); // false (1) -alert( undefined < 0 ); // false (2) -alert( undefined == 0 ); // false (3) -``` - -Why does it dislike zero so much? Always false! - -We get these results because: - -- Comparisons `(1)` and `(2)` return `false` because `undefined` gets converted to `NaN` and `NaN` is a special numeric value which returns `false` for all comparisons. -- The equality check `(3)` returns `false` because `undefined` only equals `null`, `undefined`, and no other value. - -### Avoid problems - -Why did we go over these examples? Should we remember these peculiarities all the time? Well, not really. Actually, these tricky things will gradually become familiar over time, but there's a solid way to avoid problems with them: - -- Treat any comparison with `undefined/null` except the strict equality `===` with exceptional care. -- Don't use comparisons `>= > < <=` with a variable which may be `null/undefined`, unless you're really sure of what you're doing. If a variable can have these values, check for them separately. - -## Summary - -- Comparison operators return a boolean value. -- Strings are compared letter-by-letter in the "dictionary" order. -- When values of different types are compared, they get converted to numbers (with the exclusion of a strict equality check). -- The values `null` and `undefined` equal `==` each other and do not equal any other value. -- Be careful when using comparisons like `>` or `<` with variables that can occasionally be `null/undefined`. Checking for `null/undefined` separately is a good idea. From c6ba04a467d157178dae740292056ee55efbd44a Mon Sep 17 00:00:00 2001 From: Rishav Jadon Date: Sat, 3 Oct 2020 00:06:30 +0530 Subject: [PATCH 20/22] Rename article1.md to article.md --- 1-js/02-first-steps/09-comparison/{article1.md => article.md} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename 1-js/02-first-steps/09-comparison/{article1.md => article.md} (100%) diff --git a/1-js/02-first-steps/09-comparison/article1.md b/1-js/02-first-steps/09-comparison/article.md similarity index 100% rename from 1-js/02-first-steps/09-comparison/article1.md rename to 1-js/02-first-steps/09-comparison/article.md From 77cbaa9fba2f5b67af1a48075864522d76388cf9 Mon Sep 17 00:00:00 2001 From: Rishav Jadon Date: Sat, 19 Jun 2021 13:19:54 +0530 Subject: [PATCH 21/22] Update solution.md --- .../09-comparison/1-comparison-questions/solution.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/02-first-steps/09-comparison/1-comparison-questions/solution.md b/1-js/02-first-steps/09-comparison/1-comparison-questions/solution.md index 44cf65d15..e597a795c 100644 --- a/1-js/02-first-steps/09-comparison/1-comparison-questions/solution.md +++ b/1-js/02-first-steps/09-comparison/1-comparison-questions/solution.md @@ -11,7 +11,7 @@ null === +"\n0\n" → false कुछ कारण: 1. जाहिर है, सच है। -2. शब्दकोश की तुलना, इसलिए झूठी है। `"a"` `"p"` से छोटा है। +2. यहाँ शब्दकोश की तुलना है, इसलिए गलत है। `"a"` `"p"` से छोटा है। 3. फिर से, शब्दकोश तुलना, `"2"` का पहला करैक्टर `"1"` के पहले करैक्टर से अधिक है। 4. मान `null` और `undefined` एक-दूसरे के बराबर हैं। 5. सख्त समानता सख्त है। दोनों तरफ से अलग-अलग प्रकार झूठे होते हैं। From b29e613e3418e99cd1fa63784e929dbf289d8155 Mon Sep 17 00:00:00 2001 From: Rishav Jadon Date: Sat, 19 Jun 2021 13:58:33 +0530 Subject: [PATCH 22/22] Update article.md --- 1-js/02-first-steps/09-comparison/article.md | 63 ++++++++++---------- 1 file changed, 32 insertions(+), 31 deletions(-) diff --git a/1-js/02-first-steps/09-comparison/article.md b/1-js/02-first-steps/09-comparison/article.md index e3bc3f0ef..758785fb5 100644 --- a/1-js/02-first-steps/09-comparison/article.md +++ b/1-js/02-first-steps/09-comparison/article.md @@ -1,6 +1,6 @@ # तुलना -हम गणित से कई तुलना ऑपरेटरों को जानते हैं। +हम गणित से कई तुलना प्रतीकों को जानते हैं। जावास्क्रिप्ट में वे इस तरह लिखे जाते हैं: @@ -10,25 +10,26 @@ - नहीं के बराबर है। गणित में अंकनहै, लेकिन जावास्क्रिप्ट में इसेa != b लिखा जाता है। इस लेख में हम विभिन्न प्रकार की तुलनाओं के बारे में अधिक जानेंगे, कि कैसे जावास्क्रिप्ट उन्हें महत्वपूर्ण विशिष्टता सहित बनाता है। + अंत में आपको "जावास्क्रिप्ट क्विर्क" से संबंधित मुद्दों से बचने के लिए एक अच्छा नुस्खा मिलेगा। # बुलियन परिणाम है -सभी तुलना ऑपरेटर एक बूलियन मान लौटाते हैं: +सभी तुलना प्रतीक एक बूलियन मान लौटाते हैं: -- सत्य - का अर्थ है "हाँ", "सही" या "सत्य"। -- असत्य - का अर्थ "नहीं", "गलत" या "सत्य नहीं" है। +- true - का अर्थ है "हाँ", "सही" या "सत्य"। +- false - का अर्थ "नहीं", "गलत" या "सत्य नहीं" है। उदाहरण के लिए: ``` js run -alert( 2 > 1 ); // सच (सही) -alert( 2 == 1 ); // गलत (गलत) -alert( 2 != 1 ); // सच (सही) +alert( 2 > 1 ); // true (सही) +alert( 2 == 1 ); // false (गलत) +alert( 2 != 1 ); // true (सही) ``` एक तुलना परिणाम एक चर को सौंपा जा सकता है, किसी भी मूल्य की तरह: ``` js run let result = 5 > 4; // तुलना का परिणाम बताएं -alert( result ); // सच +alert( result ); // true ``` # स्ट्रिंग तुलना @@ -38,16 +39,16 @@ alert( result ); // सच उदाहरण के लिए: ``` js run -alert( 'Z' > 'A' ); // सच -alert( 'Glow' > 'Glee' ); // सच -alert( 'Bee' > 'Be' ); // सच +alert( 'Z' > 'A' ); // true +alert( 'Glow' > 'Glee' ); // true +alert( 'Bee' > 'Be' ); // true ``` दो स्ट्रिंग की तुलना करने के लिए एल्गोरिथ्म सरल है: -1. दोनों स्ट्रिंगों के पहले चरित्र की तुलना करें। +1. दोनों स्ट्रिंगों के पहले वर्ण की तुलना करें। 2. यदि पहली स्ट्रिंग से पहला वर्ण दूसरे स्ट्रिंग की तुलना में अधिक (या कम) है, तो पहली स्ट्रिंग दूसरी की तुलना में अधिक (या कम) है। हमारा काम हो गया। -3. अन्यथा, यदि दोनों तारों के पहले चरित्र समान हैं, तो दूसरे वर्णों की तुलना उसी तरह करें। +3. अन्यथा, यदि दोनों स्ट्रिंगों का पहला वर्ण समान हैं, तो दूसरे वर्णों की तुलना उसी तरह करें। 4. स्ट्रिंग के अंत तक यही दोहराएं। 5. यदि दोनों स्ट्रिंग एक ही लंबाई में समाप्त होते हैं, तो वे समान हैं। अन्यथायही , लंबी स्ट्रिंग अधिक होती है। @@ -67,15 +68,15 @@ alert( 'Bee' > 'Be' ); // सच विभिन्न प्रकारों के मूल्यों की तुलना करते समय, जावास्क्रिप्ट मानों को संख्याओं में परिवर्तित करता है। उदाहरण के लिए: ``` js run -alert( '2' > 1 ); // सच, स्ट्रिंग '2' नंबर 2 बन जाता है -alert('01' == 1); // सच, स्ट्रिंग '01' नंबर 1 बन जाता है +alert( '2' > 1 ); // true, स्ट्रिंग '2' नंबर 2 बन जाता है +alert('01' == 1); // true, स्ट्रिंग '01' नंबर 1 बन जाता है ``` बूलियन मूल्यों के लिए, सत्य 1 हो जाता है और असत्य 0 हो जाता है। उदाहरण के लिए: ``` js run -alert ( true == 1 ); // सच -alert ( false == 0 ); // सच +alert ( true == 1 ); // true +alert ( false == 0 ); // true ``` ````smart header="A funny consequence" @@ -88,12 +89,12 @@ alert ( false == 0 ); // सच ```js run let a = 0; -alert( Boolean(a) ); // असत्य +alert( Boolean(a) ); // false let b = "0"; -alert( Boolean(a) ); // सच +alert( Boolean(a) ); // true -alert(a == b); // सच! +alert(a == b); // true! ``` जावास्क्रिप्ट के दृष्टिकोण से, यह परिणाम काफी सामान्य है। एक समानता जांच संख्यात्मक रूपांतरण का उपयोग करके मूल्यों को परिवर्तित करता है (इसलिए `"0"`, `0` बन जाता है), जबकि स्पष्ट `बुलियन` रूपांतरण नियमों के एक और सेट का उपयोग करता है। @@ -103,11 +104,11 @@ alert(a == b); // सच! एक नियमित समानता की जांच `==`में एक समस्या है। यह `0` को गलत से अलग नहीं कर सकता: ```js run -alert( 0 == false ); // सच +alert( 0 == false ); // true ``` खाली स्ट्रिंग के साथ भी यही होता है: ``` js run -alert('' == false); // सच +alert('' == false); // true ``` ऐसा इसलिए होता है क्योंकि विभिन्न प्रकार के ऑपरेंड को समानता ऑपरेटर == द्वारा संख्याओं में परिवर्तित किया जाता है। खाली स्ट्रिंग, झूठ की तरह, एक शून्य बन जाती है। @@ -119,7 +120,7 @@ alert('' == false); // सच चलो यह कोशिश करते हैं: ```js run -alert( 0 === false); // असत्य, क्योंकि प्रकार भिन्न हैं +alert( 0 === false); // false, क्योंकि प्रकार भिन्न हैं ``` एक "सख्त गैर-समानता" ऑपरेटर भी है `!==` के अनुरूप है `! =`। @@ -133,14 +134,14 @@ alert( 0 === false); // असत्य, क्योंकि प्रका : ये मूल्य अलग-अलग हैं, क्योंकि उनमें से प्रत्येक एक अलग प्रकार है। ```js run -alert( null === undefined ); // असत्य +alert( null === undefined ); // false ``` गैर-सख्त चेक के लिए `==` : एक विशेष नियम है। ये दोनों एक "स्वीट कपल" हैं: वे एक-दूसरे के बराबर (`==` के अर्थ में) हैं, लेकिन कोई दूसरा मूल्य नहीं। ```js run -alert( null == undefined ); // सच +alert( null == undefined ); // true ``` गणित और अन्य तुलनाओं के लिए `<> <=> =` @@ -151,9 +152,9 @@ alert( null == undefined ); // सच # अजीब परिणाम: नल बनाम 0 चलो `null` के साथ `0` की तुलना करें: ```js run -alert( null > 0); // (1) झूठा -alert( null == 0); // (2) झूठा -alert( null >= 0); // (3) *! * सच * /! * +alert( null > 0); // (1) false +alert( null == 0); // (2) false +alert( null >= 0); // (3) *! * true * /! * ``` गणितीय, यह अजीब है। अंतिम परिणाम में कहा गया है कि "`null` शून्य से अधिक या शून्य के बराबर है", इसलिए ऊपर की तुलनाओं में से एक में यह सच होना चाहिए, लेकिन वे दोनों झूठे हैं। @@ -165,9 +166,9 @@ alert( null >= 0); // (3) *! * सच * /! * # एक अतुलनीय ुन्डेफिनेड ुन्डेफिनेड मूल्य को अन्य मूल्यों की तुलना में नहीं किया जाना चाहिए: ```js run -alert( undefined > 0); // झूठा (1) -alert( undefined < 0); // झूठा (2) -alert( undefined == 0); // झूठा (3) +alert( undefined > 0); // false (1) +alert( undefined < 0); // false (2) +alert( undefined == 0); // false (3) ``` यह शून्य को इतना नापसंद क्यों करता है? हमेशा झूठा! pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy