Appliquer la notion
Question
Déclarer une variable potatoes
sans l'initialiser, afficher sa valeur et afficher son type.
Solution
1
/** JavaScript */
2
let potatoes
3
console.log(potatoes)
4
console.log(typeof(potatoes))
La valeur de potatoes
est undefined
et le type de potatoes
est « undefined
».
Question
Déclarer une variable potatoes
sans l'initialiser, afficher sa valeur et afficher son type, affecter la valeur 15 à potatoes
, afficher sa valeur et son type.
Indice
Il faut compléter le programme précédent.
Solution
1
/** JavaScript */
2
let potatoes
3
console.log(potatoes)
4
console.log(typeof(potatoes))
5
potatoes = 15
6
console.log(potatoes)
7
console.log(typeof(potatoes))
Avec l'affectation, potatoes
prend le type number
et peut être utilisée sans risque d'incohérence de type.