aboutsummaryrefslogtreecommitdiff
path: root/files/pt-br/web/javascript/reference/global_objects/isnan
diff options
context:
space:
mode:
authorPeter Bengtsson <mail@peterbe.com>2020-12-08 14:42:52 -0500
committerPeter Bengtsson <mail@peterbe.com>2020-12-08 14:42:52 -0500
commit074785cea106179cb3305637055ab0a009ca74f2 (patch)
treee6ae371cccd642aa2b67f39752a2cdf1fd4eb040 /files/pt-br/web/javascript/reference/global_objects/isnan
parentda78a9e329e272dedb2400b79a3bdeebff387d47 (diff)
downloadtranslated-content-074785cea106179cb3305637055ab0a009ca74f2.tar.gz
translated-content-074785cea106179cb3305637055ab0a009ca74f2.tar.bz2
translated-content-074785cea106179cb3305637055ab0a009ca74f2.zip
initial commit
Diffstat (limited to 'files/pt-br/web/javascript/reference/global_objects/isnan')
-rw-r--r--files/pt-br/web/javascript/reference/global_objects/isnan/index.html109
1 files changed, 109 insertions, 0 deletions
diff --git a/files/pt-br/web/javascript/reference/global_objects/isnan/index.html b/files/pt-br/web/javascript/reference/global_objects/isnan/index.html
new file mode 100644
index 0000000000..5e36f9da27
--- /dev/null
+++ b/files/pt-br/web/javascript/reference/global_objects/isnan/index.html
@@ -0,0 +1,109 @@
+---
+title: isNaN()
+slug: Web/JavaScript/Reference/Global_Objects/isNaN
+tags:
+ - JavaScript
+translation_of: Web/JavaScript/Reference/Global_Objects/isNaN
+---
+<div>{{jsSidebar("Objects")}}</div>
+
+<p>A função <strong><code>isNAN()</code></strong> determina se o valor é {{jsxref("Global_Objects/NaN", "NaN")}} ou não. Tenha cuidado, o <code>cast</code> em <code>isNaN</code> tem regras para serem observadas. Você pode ficar interessado no {{jsxref("Number.isNaN()")}} que foi definido no ECMAScript 6 ou você pode usar <code>typeof</code> para determinar se o valor é Not-A-Number, <code>NaN</code>.</p>
+
+<div>{{EmbedInteractiveExample("pages/js/globalprops-isnan.html")}}</div>
+
+<h2 id="Syntax" name="Syntax">Syntaxe</h2>
+
+<pre class="syntaxbox notranslate"><code>isNaN(<em>value</em>)</code></pre>
+
+<h3 id="Parâmetros">Parâmetros</h3>
+
+<dl>
+ <dt><code>value</code></dt>
+ <dd>O valor a ser testado.</dd>
+</dl>
+
+<h3 id="Valor_retornado">Valor retornado</h3>
+
+<p><strong><code>true</code></strong> se o valor for {{jsxref("NaN")}}; otherwise, <strong><code>false</code></strong>.</p>
+
+<h2 id="Description" name="Description">Descrição</h2>
+
+<h3 id="The_necessity_of_an_isNaN_function" name="The_necessity_of_an_isNaN_function">A necessidade da função <code>isNaN</code></h3>
+
+<p>Ao contrário de todas as outras possibilidades de valores no JavaScript, não é possivel confiar nos operadores de igualdade <code>(== e ===)</code> para determina se o valor é {{jsxref("Global_Objects/NaN", "NaN")}} ou não, porque ambos, <code>NaN == NaN e NaN === NaN</code>, terá como valor de retorno:<code> false</code>. Daí a necessidade da funçao <code>isNAN</code>.</p>
+
+<h3 id="Origin_of_NaN_values" name="Origin_of_NaN_values">Origem dos valores <code>NaN</code></h3>
+
+<p>Os valores <code>NaN</code> são gerados quando operações aritiméticas tem como valores: <em>undefined</em> ou<em> unrepresentable</em>. Como valores, não fazem necessariamente condições de estouro. <code>NaN</code> também resulta da tentativa de coerção para valores numéricos, de valores não numéricos, para que o valor numérico primitivo seja disponível.</p>
+
+<p>Por exemplo, divida zero por zero e o resultado será <code>NaN</code> , mas se dividir outros números por zero ele não será.</p>
+
+<h3 id="Comportamento_confuso_do_caso_especial">Comportamento confuso do caso especial</h3>
+
+<p><span id="result_box" lang="pt"><span title="Since the very earliest versions of the isNaN function specification, its behavior for non-numeric arguments has been confusing.">Desde as primeiras versões da especificação da função isNaN , o seu comportamento para argumentos não numéricos tem sido confuso. </span><span title="When the argument to the isNaN function is not of type Number, the value is first coerced to a Number.">Quando o argumento para a função <code>isNaN</code> não é do tipo<em> </em></span></span><em><span id="result_box" lang="pt"><span title="When the argument to the isNaN function is not of type Number, the value is first coerced to a Number.">Numbe</span></span></em><span id="result_box" lang="pt"><span title="When the argument to the isNaN function is not of type Number, the value is first coerced to a Number."><em>r</em>, o valor é primeiro convertido para um número. </span><span title='The resulting value is then tested to determine whether it is {{jsxref("Global_Objects/NaN", "NaN")}}.'>O valor resultante é em seguida testado para determinar se se trata de</span></span><span lang="pt"><span title='The resulting value is then tested to determine whether it is {{jsxref("Global_Objects/NaN", "NaN")}}.'> </span></span>{{jsxref("Number.isNaN()")}}. <span lang="pt"><span title='Thus for non-numbers that when coerced to numeric type result in a valid non-NaN numeric value (notably the empty string and boolean primitives, which when coerced give numeric values zero or one), the "false" returned value may be unexpected;'>Assim, para os não-números que quando forçados ao tipo numérico resultado em um valor numérico não-<code>NaN</code> válido (particularmente strings vazias e primitivas booleanas, que quando submetidas ao <code>cast</code> dão valores numéricos zero ou um), o "falso" valor retornado pode ser inesperado; </span><span title='the empty string, for example, is surely "not a number."'>a cadeia vazia , por exemplo, é certamente "not-a-number" </span><span title='The confusion stems from the fact that the term, "not a number", has a specific meaning for numbers represented as IEEE-794 floating-point values.'>A confusão decorre do fato de que o termo, " não é um número " , tem um significado específico para os números representados como valores de ponto flutuante IEEE- 794 . </span><span title="The function should be interpreted as answering the question, &quot;is this value, when coerced to a numeric value, an IEEE-794 'Not A Number' value?&quot;">A função deve ser interpretada como respondendo à pergunta: "este valor, quando convertido para um valor numérico, um valor IEEE -794 ' not-a-number"?</span></span></p>
+
+<p>A ultima versão do ECMAScript (ES6) contém A função {{jsxref("Number.isNaN()")}}. <code>Number.isNaN(x)</code> será a real forma para testar se x é NaN ou não. Mesmo com <code>Number.isNaN</code>, porém, o significado de NaN continua ser a precisão numérica, e não simplesmente, "não é um número = <code>NaN</code>, <em>not a number</em>". Paralelamente , na expressão <code>Number.isNaN</code>, a expressão<code> (x != x)</code> é a forma mais confiável para testar se a variável <code>x </code>é<code> NaN</code> ou não, assim o resultado não é sujeito ao falso positivo que faz <code>isNaN</code> não ser confiável.</p>
+
+<p>A polyfill for <code>isNaN</code> would be (the polyfill leverages the unique never-equal-to-itself characteristic of <code>NaN</code>):</p>
+
+<pre class="brush: js notranslate">var isNaN = function(value) {
+    var n = Number(value);
+    return n !== n;
+};</pre>
+
+<h2 id="Examples" name="Examples">Exemplos</h2>
+
+<pre class="brush: js notranslate">isNaN(NaN); // true
+isNaN(undefined); // true
+isNaN({}); // true
+
+isNaN(true); // false
+isNaN(null); // false
+isNaN(37); // false
+
+// strings
+isNaN("37"); // false: "37" is converted to the number 37 which is not NaN
+isNaN("37.37"); // false: "37.37" is converted to the number 37.37 which is not NaN
+isNaN(""); // false: the empty string is converted to 0 which is not NaN
+isNaN(" "); // false: a string with spaces is converted to 0 which is not NaN
+
+// dates
+isNaN(new Date()); // false
+isNaN(new Date().toString()); // true
+
+// Esse é um falso positivo e é a razão para isNaN não seja totalmente confiável.
+isNaN("blabla") // true: "blabla" é convertido para número.
+ // A análise desse número falha e retorna NaN como resultado.
+</pre>
+
+<h3 id="Useful_special-case_behavior">Useful special-case behavior</h3>
+
+<p>There is a more usage oriented way to think of <code>isNaN()</code>: If <code>isNaN(x)</code> returns <code>false</code>, you can use <code>x</code> in an arithmetic expression not making the expression return <code>NaN</code>. If it returns <code>true</code>, <code>x</code> will make every arithmetic expression return <code>NaN</code>. This means that in JavaScript, <code>isNaN(x) == true</code> is equivalent to <code>x - 0</code> returning <code>NaN</code> (though in JavaScript <code>x - 0 == NaN</code> always returns false, so you can't test for it). Actually, <code>isNaN(x)</code>, <code>isNaN(x - 0)</code>, <code>isNaN(Number(x))</code>, <code>Number.isNaN(x - 0)</code>, and <code>Number.isNaN(Number(x))</code> always return the same and in JavaScript <code>isNaN(x)</code> is just the shortest possible form to express each of these terms.</p>
+
+<p>You can use this, for example, to test whether an argument to a function is arithmetically processable (usable "like" a number), or if it's not and you have to provide a default value or something else. This way you can have a function that makes use of the full versatility JavaScript provides by implicitly converting values depending on context.</p>
+
+<h2 id="Specifications">Specifications</h2>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <th scope="col">Specification</th>
+ </tr>
+ <tr>
+ <td>{{SpecName('ESDraft', '#sec-isnan-number', 'isNaN')}}</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="Browser_compatibility">Browser compatibility</h2>
+
+
+
+<p>{{Compat("javascript.builtins.isNaN")}}</p>
+
+<h2 id="See_also" name="See_also">Veja também</h2>
+
+<ul>
+ <li>{{jsxref("NaN")}}</li>
+ <li>{{jsxref("Number.isNaN()")}}</li>
+</ul>