में इसके विशिष्ट विवरण और परिणाम प्राप्त करेंगे।
```
-## 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