From 39f2114f9797eb51994966c6bb8ff1814c9a4da8 Mon Sep 17 00:00:00 2001 From: Florian Merz Date: Thu, 11 Feb 2021 12:36:08 +0100 Subject: unslug fr: move --- .../erreurs/cant_access_property/index.html | 59 ---------------------- 1 file changed, 59 deletions(-) delete mode 100644 files/fr/web/javascript/reference/erreurs/cant_access_property/index.html (limited to 'files/fr/web/javascript/reference/erreurs/cant_access_property/index.html') 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 ---- -
{{jsSidebar("Errors")}}
- -

Message

- -
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
-
- -

Types d'erreur

- -

{{jsxref("TypeError")}}.

- -

Quel est le problème ?

- -

On a tenté d'accéder à une propriété sur la valeur {{jsxref("undefined")}} ou {{jsxref("null")}}.

- -

Exemples

- -

Cas invalides

- -
// 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
-
- -

Corriger le problème

- -

Pour détecter le cas où la valeur utilisée est undefined ou null, on peut utiliser l'opérateur typeof. Par exemple :

- -
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.
-}
- -

Voir aussi

- - -- cgit v1.2.3-54-g00ecf