aboutsummaryrefslogtreecommitdiff
path: root/files/pl/web/javascript/referencje/obiekty/number/isnan/index.html
blob: ddb723b4099c8f644fc9e72d140dd1f0ce78639f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
---
title: Number.isNaN()
slug: Web/JavaScript/Referencje/Obiekty/Number/isNaN
tags:
  - ECMAScript 2015
  - JavaScript
  - Metodă
  - NaN
  - Number
  - isNaN
translation_of: Web/JavaScript/Reference/Global_Objects/Number/isNaN
---
<div>{{JSRef}}</div>

<p>Metoda <strong><code>Number.isNaN()</code></strong> określa czy podany parametr ma wartość {{jsxref("NaN")}} i czy jest typu {{jsxref("Number")}}. Jest to ulepszona wersja oryginalnej, globalne funkcji {{jsxref("isNaN", "isNaN()")}}.</p>

<div>{{EmbedInteractiveExample("pages/js/number-isnan.html", "taller")}}</div>

<div class="hidden">The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone <a href="https://github.com/mdn/interactive-examples">https://github.com/mdn/interactive-examples</a> and send us a pull request.</div>

<h2 id="Składnia">Składnia</h2>

<pre class="syntaxbox"><code>Number.isNaN(<var>value</var>)</code></pre>

<h3 id="Parametry">Parametry</h3>

<dl>
 <dt><code><var>value</var></code></dt>
 <dd>Wartość, którą będziemy testować {{jsxref("NaN")}}.</dd>
</dl>

<h3 id="Zwracana_wartość">Zwracana wartość</h3>

<p><strong>true</strong>, jeśli podana wartość jest {{jsxref("NaN")}}, a jej typem jest {{jsxref("Number")}}; w przeciwnym razie, <strong>false</strong>.</p>

<h2 id="Opis">Opis</h2>

<p>Ponieważ oba operatory porównania, {{jsxref("Operators/Comparison_Operators", "==", "#Equality")}} i {{jsxref("Operators/Comparison_Operators", "===", "#Identity")}}, dla zapytania czy {{jsxref("NaN")}} <em>jest równe</em> {{jsxref("NaN")}} zwracają <code>false</code> funkcja <code>Number.isNaN()</code> staje się niezbędna. Jest sytuacja wyjątkowa i nie występuje, gdy porównujemy dowolne inne wartości w języku JavaScript.</p>

<p>W porównaniu do funkcji globalnej {{jsxref("isNaN", "isNaN()")}}, metoda <code>Number.isNaN()</code> nie ma problemu z usilnym konwertowaniem parametru na liczbę. To oznacza, że można bezpiecznie przekazywać wartości, które normalnie mogłyby zostać skonwertowane na {{jsxref("NaN")}}, ale nie mają tej samej wartości co {{jsxref("NaN")}}. To również oznacza, że jedynie wartości typu {{jsxref("Number")}}, które są również {{jsxref("NaN")}}, zwrócą <code>true</code>.</p>

<h2 id="Przykłady">Przykłady</h2>

<pre class="brush: js">Number.isNaN(NaN);        // true
Number.isNaN(Number.NaN); // true
Number.isNaN(0 / 0);      // true

// Gdybyśmy użyli funkcji isNaN(), te przykłady zwróciłby true
Number.isNaN('NaN');      // false
Number.isNaN(undefined);  // false
Number.isNaN({});         // false
Number.isNaN('blabla');   // false

// Wszystkie zwracają false
Number.isNaN(true);
Number.isNaN(null);
Number.isNaN(37);
Number.isNaN('37');
Number.isNaN('37.37');
Number.isNaN('');
Number.isNaN(' ');
</pre>

<h2 id="Polyfill">Polyfill</h2>

<p>Następujący przykład działa, ponieważ {{jsxref("NaN")}} jest jedyną wartością w języku JavaScript, która nie jest równa samej sobie.</p>

<pre class="brush: js">Number.isNaN = Number.isNaN || function(value) {
    return value !== null &amp;&amp; (value != value || +value != value);
}
</pre>

<h2 id="Opis_2">Opis</h2>

<table class="standard-table">
 <thead>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>{{SpecName('ESDraft', '#sec-number.isnan', 'Number.isnan')}}</td>
   <td>{{Spec2('ESDraft')}}</td>
   <td></td>
  </tr>
  <tr>
   <td>{{SpecName('ES2015', '#sec-number.isnan', 'Number.isnan')}}</td>
   <td>{{Spec2('ES2015')}}</td>
   <td>Initial definition.</td>
  </tr>
 </tbody>
</table>

<h2 id="Kompatybilność">Kompatybilność</h2>



<div>{{Compat("javascript.builtins.Number.isNaN")}}</div>

<h2 id="Zobacz_również">Zobacz również</h2>

<ul>
 <li>{{jsxref("Number")}}</li>
 <li>{{jsxref("isNaN", "isNaN()")}}</li>
</ul>