Bonjour à tous,

Voici mon code simple et complet:

Code html : Sélectionner tout - Visualiser dans une fenêtre à part
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
<!doctype html>
 
<html>
 
	<head>
		<title>Afficher un nom</title>
		<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
		<meta charset='utf8'>
	</head>
 
	<body>
 
 
	<script>
        
        $(function(){
 
        var variableGlobale = "Je suis une variable globale";
        
        function afficher_variableGlobale(){
        
                alert(variableGlobale);
        }
 
        afficher_variableGlobale();
        });
        </script>
 
 
 
	</body>
 
</html>

Et voici ma question:
Pourquoi si je déclare la fonction
Code : Sélectionner tout - Visualiser dans une fenêtre à part
afficher_variableGlobale()
hors de la fonction anonyme JQuery ma variable globale n'est plus reconnue?

Sincère reconnaissance à toute personne pouvant m'apporter une réponse.
Cordialement.