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 a86a9f73e..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 @@ -1,5 +1,4 @@ - ```js no-beautify 5 > 4 → true "apple" > "pineapple" → false @@ -9,13 +8,12 @@ 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. +1. जाहिर है, सच है। +2. यहाँ शब्दकोश की तुलना है, इसलिए गलत है। `"a"` `"p"` से छोटा है। +3. फिर से, शब्दकोश तुलना, `"2"` का पहला करैक्टर `"1"` के पहले करैक्टर से अधिक है। +4. मान `null` और `undefined` एक-दूसरे के बराबर हैं। +5. सख्त समानता सख्त है। दोनों तरफ से अलग-अलग प्रकार झूठे होते हैं। +6. `(4)` के समान, `null` केवल `undefined` के बराबर है। +7. विभिन्न प्रकार की सख्त समानता। 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 index be7f75ddd..a2f9fa3d7 100644 --- 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 @@ -2,9 +2,9 @@ importance: 5 --- -# Comparisons +# तुलना -What will be the result for these expressions? +इन भावों का परिणाम क्या होगा? ```js no-beautify 5 > 4 @@ -16,3 +16,4 @@ null == "\n0\n" null === +"\n0\n" ``` + diff --git a/1-js/02-first-steps/09-comparison/article.md b/1-js/02-first-steps/09-comparison/article.md index a323dc93d..758785fb5 100644 --- a/1-js/02-first-steps/09-comparison/article.md +++ b/1-js/02-first-steps/09-comparison/article.md @@ -1,214 +1,192 @@ -# 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. +- ग्रेटर / से कम: a > b, a < b। +- ग्रेटर / से कम या बराबर: a >= b, a <= b। +- समतुल्य: `a == b`, कृपया दोहरे समानता चिन्ह पर ध्यान दें `==` का अर्थ है समानता परीक्षण, जबकि एकल `a = b` का अर्थ है असाइनमेंट। +- नहीं के बराबर है। गणित में अंकनहै, लेकिन जावास्क्रिप्ट में इसे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 - का अर्थ है "हाँ", "सही" या "सत्य"। +- false - का अर्थ "नहीं", "गलत" या "सत्य नहीं" है। -- `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) +उदाहरण के लिए: +``` js run +alert( 2 > 1 ); // true (सही) +alert( 2 == 1 ); // false (गलत) +alert( 2 != 1 ); // true (सही) ``` -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 +एक तुलना परिणाम एक चर को सौंपा जा सकता है, किसी भी मूल्य की तरह: +``` js run +let result = 5 > 4; // तुलना का परिणाम बताएं 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 +उदाहरण के लिए: +``` 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. +1. दोनों स्ट्रिंगों के पहले वर्ण की तुलना करें। +2. यदि पहली स्ट्रिंग से पहला वर्ण दूसरे स्ट्रिंग की तुलना में अधिक (या कम) है, तो पहली स्ट्रिंग दूसरी की तुलना में अधिक (या कम) है। हमारा काम हो गया। +3. अन्यथा, यदि दोनों स्ट्रिंगों का पहला वर्ण समान हैं, तो दूसरे वर्णों की तुलना उसी तरह करें। +4. स्ट्रिंग के अंत तक यही दोहराएं। +5. यदि दोनों स्ट्रिंग एक ही लंबाई में समाप्त होते हैं, तो वे समान हैं। अन्यथायही , लंबी स्ट्रिंग अधिक होती है। -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: +ऊपर दिए गए उदाहरणों में, `'Z'> 'A'` की तुलना पहले चरण में होती है जबकि `"Glow"` और `"Glee"` वर्ण-दर-वर्ण की तुलना की जाती है: -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. +1. `G`, `G` के समान है। +2. `l`, `l` के समान है। +3. `o`, `e` से बड़ा है। यहाँ रुको। पहली स्ट्रिंग अधिक होती है। ```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 . +मसलन, मामला मायने रखता है। एक कैपिटल लेटर `'A'` लोअरकेस `'a' 'के बराबर नहीं है। कौन सा अधिक है? लोअरकेस `'a'`। क्यों? क्योंकि आंतरिक एन्कोडिंग तालिका जावास्क्रिप्ट उपयोग (यूनिकोड) में लोअरकेस वर्ण का एक बड़ा सूचकांक है। हम अध्याय में इसके विशिष्ट विवरण और परिणाम प्राप्त करेंगे। ``` -## 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 +# विभिन्न प्रकारों की तुलना +विभिन्न प्रकारों के मूल्यों की तुलना करते समय, जावास्क्रिप्ट मानों को संख्याओं में परिवर्तित करता है। +उदाहरण के लिए: +``` js run +alert( '2' > 1 ); // true, स्ट्रिंग '2' नंबर 2 बन जाता है +alert('01' == 1); // true, स्ट्रिंग '01' नंबर 1 बन जाता है ``` +बूलियन मूल्यों के लिए, सत्य 1 हो जाता है और असत्य 0 हो जाता है। -For boolean values, `true` becomes `1` and `false` becomes `0`. - -For example: - -```js run -alert( true == 1 ); // true -alert( false == 0 ); // true +उदाहरण के लिए: +``` 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( Boolean(a) ); // 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. +जावास्क्रिप्ट के दृष्टिकोण से, यह परिणाम काफी सामान्य है। एक समानता जांच संख्यात्मक रूपांतरण का उपयोग करके मूल्यों को परिवर्तित करता है (इसलिए `"0"`, `0` बन जाता है), जबकि स्पष्ट `बुलियन` रूपांतरण नियमों के एक और सेट का उपयोग करता है। ```` -## Strict equality - -A regular equality check `==` has a problem. It cannot differentiate `0` from `false`: +# सख्त समानता +एक नियमित समानता की जांच `==`में एक समस्या है। यह `0` को गलत से अलग नहीं कर सकता: ```js run alert( 0 == false ); // true ``` - -The same thing happens with an empty string: - -```js run -alert( '' == false ); // true +खाली स्ट्रिंग के साथ भी यही होता है: +``` 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`? +अगर हम असत्य से `0` को अलग करना चाहते हैं तो क्या करें? -**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: +दूसरे शब्दों में, यदि `a` और `b` अलग-अलग प्रकार के हैं, तो `a === b` तुरंत उन्हें बदलने के प्रयास के बिना झूठा लौट आता है। +चलो यह कोशिश करते हैं: ```js run -alert( 0 === false ); // false, because the types are different +alert( 0 === false); // false, क्योंकि प्रकार भिन्न हैं ``` -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 - ``` +```js run +alert( null === undefined ); // false +``` -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. +```js run +alert( null == undefined ); // true +``` -### Strange result: null vs 0 +गणित और अन्य तुलनाओं के लिए `<> <=> =` +: नल / ुन्डेफिनेड संख्या में परिवर्तित हो जाते हैं: `null` 0 हो जाता है, जबकि `undefined` `NaN` हो जाता है। -Let's compare `null` with a zero: +अब देखते हैं कुछ मजेदार चीजें, जो तब होती हैं, जब हम इन नियमों को लागू करते हैं। और, क्या अधिक महत्वपूर्ण है, कैसे उनके साथ एक जाल में नहीं पड़ना। +# अजीब परिणाम: नल बनाम 0 +चलो `null` के साथ `0` की तुलना करें: ```js run -alert( null > 0 ); // (1) false -alert( null == 0 ); // (2) false -alert( null >= 0 ); // (3) *!*true*/!* +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. +गणितीय, यह अजीब है। अंतिम परिणाम में कहा गया है कि "`null` शून्य से अधिक या शून्य के बराबर है", इसलिए ऊपर की तुलनाओं में से एक में यह सच होना चाहिए, लेकिन वे दोनों झूठे हैं। -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. +कारण यह है कि एक समानता जांच `==` और तुलना `> <> = <=` अलग तरीके से काम करते हैं। तुलना शून्य को एक संख्या में बदल देती है, इसे `0` मानते हैं। इसीलिए (3) `null> = 0` सत्य है और (1) `null> 0` मिथ्या है। -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: +दूसरी ओर, `null` और `undefined` के लिए समानता की जांच `==` को ऐसे परिभाषित किया गया है, बिना किसी रूपांतरण के, वे एक-दूसरे के बराबर हैं और किसी अन्य चीज़ के बराबर नहीं हैं। इसीलिए (2) `null == 0` असत्य है। +# एक अतुलनीय ुन्डेफिनेड + ुन्डेफिनेड मूल्य को अन्य मूल्यों की तुलना में नहीं किया जाना चाहिए: ```js run -alert( undefined > 0 ); // false (1) -alert( undefined < 0 ); // false (2) -alert( undefined == 0 ); // false (3) +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: +- तुलना (1) और (2) झूठी हो जाती है क्योंकि `undefined` `NaN` में परिवर्तित हो जाता है और `NaN` एक विशेष संख्यात्मक मान होता है जो सभी तुलनाओं के लिए गलत होता है। +- समानता की जांच (3) झूठी होती है क्योंकि `undefined` केवल `null` और `undefined` के बराबर होता है। -- 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 +- असाधारण देखभाल के साथ सख्त समानता `===` को छोड़कर `undefined/null` के साथ किसी भी तुलना का व्यवहार करें। +- तुलना का उपयोग न करें `> => <<=` एक वेरिएबल के साथ जो `undefined/null` हो सकता है, जब तक कि आप वास्तव में निश्चित नहीं हैं कि आप क्या कर रहे हैं। यदि किसी वेरिएबल में ये मान हो सकते हैं, तो उनके लिए अलग से जाँच करें। -- 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. +# सारांश +- तुलना ऑपरेटर एक बूलियन मान लौटाते हैं। +- स्ट्रिंग्स की तुलना "शब्दकोश" क्रम में अक्षर-दर-अक्षर से की जाती है। +- जब विभिन्न प्रकारों के मूल्यों की तुलना की जाती है, तो वे संख्याओं में परिवर्तित हो जाते हैं (एक सख्त समानता जांच के बहिष्करण के साथ)। +- मान, `null`और `undefined` समान `==` एक दूसरे के, और किसी भी अन्य मूल्य के बराबर नहीं है। +- वैरिएबल के साथ `>` या `<` जैसे तुलनाओं का उपयोग करते समय सावधान रहें जो कभी-कभी `undefined/null` हो सकते हैं। `undefined/null` के लिए अलग से जाँच करना एक अच्छा विचार है। 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