aboutsummaryrefslogtreecommitdiff
path: root/files/pt-br/web/javascript/reference/errors/cant_access_property
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/errors/cant_access_property
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/errors/cant_access_property')
-rw-r--r--files/pt-br/web/javascript/reference/errors/cant_access_property/index.html60
1 files changed, 60 insertions, 0 deletions
diff --git a/files/pt-br/web/javascript/reference/errors/cant_access_property/index.html b/files/pt-br/web/javascript/reference/errors/cant_access_property/index.html
new file mode 100644
index 0000000000..7c5c9affa3
--- /dev/null
+++ b/files/pt-br/web/javascript/reference/errors/cant_access_property/index.html
@@ -0,0 +1,60 @@
+---
+title: 'TypeError: can''t access property "x" of "y"'
+slug: Web/JavaScript/Reference/Errors/Cant_access_property
+tags:
+ - Erros
+ - JavaScript
+ - TypeError
+translation_of: Web/JavaScript/Reference/Errors/Cant_access_property
+---
+<div>{{jsSidebar("Errors")}}</div>
+
+<h2 id="Mensagem">Mensagem</h2>
+
+<pre class="syntaxbox">TypeError: Unable to get property {x} of undefined or null reference (Edge)
+TypeError: can't access property {x} of {y} (Firefox)
+TypeError: {y} is undefined, can't access property {x} of it (Firefox)
+TypeError: {y} is null, can't access property {x} of it (Firefox)
+
+Exemplos:
+TypeError: x is undefined, can't access property "prop" of it
+TypeError: x is null, can't access property "prop" of it
+TypeError: can't access property "prop" of undefined
+TypeError: can't access property "prop" of null
+</pre>
+
+<h2 id="Tipo_de_Erro">Tipo de Erro</h2>
+
+<p>{{jsxref("TypeError")}}.</p>
+
+<h2 id="O_que_deu_errado">O que deu errado?</h2>
+
+<p>O acesso a propriedade foi realizado com um valor {{jsxref("undefined")}} ou {{jsxref("null")}}.</p>
+
+<h2 id="Exemplos">Exemplos</h2>
+
+<h3 id="Casos_inválidos">Casos inválidos</h3>
+
+<pre class="brush: js example-bad">// casos undefined e null, onde o metódo substring não irá funcionar
+
+var foo = undefined;
+foo.substring(1); // TypeError: x is undefined, can't access property "substring" of it
+
+var foo = null;
+foo.substring(1); // TypeError: x is null, can't access property "substring" of it
+</pre>
+
+<h3 id="Corrigindo_o_problema">Corrigindo o problema</h3>
+
+<p>Para corrigir o problema de valores <code>undefined</code> ou <code>null</code>,  você pode usar o operador <a href="/en-US/docs/Web/JavaScript/Reference/Operators/typeof">typeof</a>, como no exemplo abaixo.</p>
+
+<pre class="brush: js">if (typeof foo !== 'undefined') {
+ // Agora que sabemos que <em>foo</em> está definida, podemos prosseguir
+}</pre>
+
+<h2 id="Veja_também">Veja também</h2>
+
+<ul>
+ <li>{{jsxref("undefined")}}</li>
+ <li>{{jsxref("null")}}</li>
+</ul>