should give an error when you attempt to run this code. Because appetizers is now a undefined variable.
we can only help you, in the end, you will have to get to the finish. To achieve this, its important to teach yourself thinking steps like: what do i try to do here? How can achieve this? Which methods do i have to achieve this?
I understand the difference between dot notation and bracket notation… I don’t understand why we pass a string into bracket notation… If you pass a variable in, it would just give you the key right? Does appetizers return undefined because it is an empty array?
With bracket notation you can also use a variable inside the brackets to select the keys of an object. So, passing in appetizers (without ‘’) passes it as a key, and doesn’t give us a value.
we get the value, appetizers is the key, we use the key to do a lookup, resulting in the value
why would it go from one data type (array) to another data type (undefined)?
a variable has a value (for example a string), like in my example:
theKey = 'myKey'
which we can use as key to lookup a value in the object using the associative array notation.
In the meal maker project, you pass 'appetizers' string as argument to courseName parameter, so now we have a variable (courseName) with a string value (’appetizers’`) which we can use as key to get value from the object
It is called associate array notation because you have to declare strings when accessing an element in an array. For instance,
var cars = [“Saab”, “Volvo”, “BMW”];
We can access “Volvo” with cars… 1 is a number data type, but with objects, we use strings like menu._courses[“appetizers”]. “appetizers” is a string data type. Does this mean that objects are not all indexed like arrays. Even though all arrays are objects but not all objects are arrays?