Skip to content

Commit 18c60e7

Browse files
authored
Fix address object access to retrieve house number
1 parent de6889c commit 18c60e7

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

‎Sprint-2/debug/address.js‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,23 @@ const address = {
1313
};
1414

1515
console.log(`My house number is ${address[0]}`);
16+
17+
//my prediction is "undefined" because objects use names. When we js executes this code it is seeing address[0], it looks
18+
//for 0 in objects, won't find it and will return , undefined.
19+
20+
// i have run the code in devtools and got the "My house number is undefined" message.
21+
22+
//the fixed code
23+
24+
const address = {
25+
houseNumber: 42,
26+
street: "Imaginary Road",
27+
city: "Manchester",
28+
country: "England",
29+
postcode: "XYZ 123",
30+
};
31+
32+
console.log(`My house number is ${address.houseNumber}`);
33+
34+
35+

0 commit comments

Comments
 (0)