diff options
| author | Florian Merz <me@fiji-flo.de> | 2021-02-11 12:36:08 +0100 |
|---|---|---|
| committer | Florian Merz <me@fiji-flo.de> | 2021-02-11 12:36:08 +0100 |
| commit | 39f2114f9797eb51994966c6bb8ff1814c9a4da8 (patch) | |
| tree | 66dbd9c921f56e440f8816ed29ac23682a1ac4ef /files/fr/web/javascript/reference/erreurs/cant_access_property/index.html | |
| parent | 8260a606c143e6b55a467edf017a56bdcd6cba7e (diff) | |
| download | translated-content-39f2114f9797eb51994966c6bb8ff1814c9a4da8.tar.gz translated-content-39f2114f9797eb51994966c6bb8ff1814c9a4da8.tar.bz2 translated-content-39f2114f9797eb51994966c6bb8ff1814c9a4da8.zip | |
unslug fr: move
Diffstat (limited to 'files/fr/web/javascript/reference/erreurs/cant_access_property/index.html')
| -rw-r--r-- | files/fr/web/javascript/reference/erreurs/cant_access_property/index.html | 59 |
1 files changed, 0 insertions, 59 deletions
diff --git a/files/fr/web/javascript/reference/erreurs/cant_access_property/index.html b/files/fr/web/javascript/reference/erreurs/cant_access_property/index.html deleted file mode 100644 index 88e96eebef..0000000000 --- a/files/fr/web/javascript/reference/erreurs/cant_access_property/index.html +++ /dev/null @@ -1,59 +0,0 @@ ---- -title: 'TypeError: can''t access property "x" of "y"' -slug: Web/JavaScript/Reference/Erreurs/Cant_access_property -tags: - - Erreurs - - JavaScript - - TypeError -translation_of: Web/JavaScript/Reference/Errors/Cant_access_property ---- -<div>{{jsSidebar("Errors")}}</div> - -<h2 id="Message">Message</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) - -Exemples -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="Types_d'erreur">Types d'erreur</h2> - -<p>{{jsxref("TypeError")}}.</p> - -<h2 id="Quel_est_le_problème">Quel est le problème ?</h2> - -<p>On a tenté d'accéder à une propriété sur la valeur {{jsxref("undefined")}} ou {{jsxref("null")}}.</p> - -<h2 id="Exemples">Exemples</h2> - -<h3 id="Cas_invalides">Cas invalides</h3> - -<pre class="brush: js example-bad">// undefined et null ne possèdent aucune propriété et aucune méthode substring -var toto = undefined; -toto.substring(1); // TypeError: x is undefined, can't access property "substring" of it - -var toto = null; -toto.substring(1); // TypeError: x is null, can't access property "substring" of it -</pre> - -<h3 id="Corriger_le_problème">Corriger le problème</h3> - -<p>Pour détecter le cas où la valeur utilisée est <code>undefined</code> ou <code>null</code>, on peut utiliser l'opérateur <code><a href="/fr/docs/Web/JavaScript/Reference/Opérateurs/L_opérateur_typeof">typeof</a></code>. Par exemple :</p> - -<pre class="brush: js">if (typeof toto !== 'undefined') { - // On sait alors que toto est bien défini et on peut utiliser ses propriétés s'il en a. -}</pre> - -<h2 id="Voir_aussi">Voir aussi</h2> - -<ul> - <li>{{jsxref("undefined")}}</li> - <li>{{jsxref("null")}}</li> -</ul> |
