Quiz

  1. For question #4, I picked D, because I thought if you wanted to A, you would have to put age in quotes. 

    That question was:

            
    To retrieve the "age" property from an object stored
    in a variable called "person1," you would use:
        A. person1[age]
        B. person1{age}
        C. age.person1
        D. person1.age
    

    You are correct. If I want the "age" property using the bracket syntax, I have to use person1["age"]

  2. Could we discuss more about the differences in the forEach and .map() and when its best to use each?

    Sure. One main difference: map collects and returns an array of the return values values; it's all about the return values of the callback function. forEach ignores the return values and returns nothing.

  3. more practice of the forEach method

    I put some in the lecture notes.

  4. I was wondering if the forEach method is like a for loop ? I'm a bit confused as to how it takes in a function as well.

    Yes, it's like a loop. The callback function is like the body of the loop: it's the stuff that is done for each element.

  5. I would love to review the array methods in class / could we revisit array methods. thanks!

    Sure; let's look at the array methods section of the reading.

  6. Is it possible for an object to have a property that is a function?

    Yes! (We don't be getting into OOP in this course, but that's how it's done!)

  7. JavaScript methods. One of the main differences from python, in my opinion, is the frequency with which the syntax "noun.verb(params)" pops up.

    Frequency really isn't the issue. Both languages have objects with methods and these are used in normal programming; they're not weird or exotic. (Take a look at the Python DateTime Objects; the word "method" occurs 36 times on that page.

    The important thing is that you feel comfortable using methods. That's why we practice with dates and arrays.

  8. I think I understand how objects work, but I thought we were already dealing with objects - like is a list an object? It has methods, so I'm assuming yes, but it's generalizable in a way that the examples from the reading weren't. Can we make our own generalizable objects?

    The terminology is unfortunate. Yes, in JavaScript, as in Java, pretty much everything is an object. But we also have objects that act like dictionaries. So, while lists (arrays) are objects (and have methods and such), we need a term for the dictionary objects. The standard is just to call them "objects" and hope the reader can figure it out from context.

    I'm going to call them dictionaries, even though that's not standard.

    When we get to MongoDB, they might be called documents.

    Yes, we can make our own objects, but this course is not going to cover OOP in JavaScript unless you want me to. We can do it at the end of the course.

  9. I think some practice working with objects would be helpful. Highlighting the differences between dictionaries and objects would be good.

    I'll add some more practice problems.

    Differences between Python dictionaries and JavaScript object literals (AKA dictionaries) are very few. Python dictionaries have a few methods that JavaScript dictionaries don't, but the basic square bracket syntax to read and store is identical:

    dic['a'] = 3; print(dic['a'])

    There is the dot notation which is nice and only available in JavaScript

    dic.a = 3; print(dic.a)
  10. I would like to talk about dot notation and the shortcuts that come with it. It is a bit confusing, and I would like to get a better understanding.

    For sure. The dot notation is used when we have a constant as the key: in other words, the programmer knows what key they want. This covers the vast majority of cases.

    If, on the other hand, the key is unknown, maybe chosen by the user or computed from something else, we must use the square bracket notation, and put the variable in the square brackets.

  11. Unknown properties / I'd love to learn more about unknown properties

    Again, rare, but it does happen. We'll see some examples.

  12. Everything was pretty straightforward!

    I'm glad!