Tell us what’s happening:
what is the key differentiation of using animal[‘habitat’] and animal.habitat ?
Your code so far
const tiger = {
species: "Tiger",
age: 5,
isEndangered: true
};
const elephant = {
species: "Elephant",
age: 10,
isEndangered: true
};
const getSpecies = (animal) => {
return animal.species;
};
console.log(getSpecies(tiger));
const getAge = (animal) => {
return animal.age;
};
console.log(getAge(tiger));
// User Editable Region
const addHabitat = (animal, habitat) => {
animal['habitat'] = habitat;
return animal;
}
console.log(addHabitat(tiger, 'Rainforest'));
// User Editable Region
Your browser information:
User Agent is: Mozilla/5.0 (X11; Linux x86_64; rv:152.0) Gecko/20100101 Firefox/152.0
Challenge Information:
Build a Wildlife Tracker - Step 8
GitHub Link: freeCodeCamp/curriculum/challenges/english/blocks/workshop-wildlife-tracker/6999ad1cdc249e185aaeedbd.md at main · freeCodeCamp/freeCodeCamp · GitHub
ILM
2
they do the same thing
using the square bracket syntax offers more flexibility that the dot notation does not have
obj["name"] // string - equivalent of obj.name
obj["first name"] // string with space
obj[5562] // number
obj[prop] // variable
only the first one has an equivalent dot notation, the others aren’t things that dot notation can do
I have opened this issue