Quiz

  1. 
    var p1 = {'name': 'Alice', 'gradYear': 2019, 'going': 'no'};
    var p1_keys = Object.keys(p1);
    p1_keys.forEach(function (k) { console.log(p1[k])});
    
    

    Could you talk more about the anonymous function (k) here? Why do we need to define this anonymous function in forEach() method?

    I'd be glad to. This is always a tricky one. The anonymous function is being invoked for each key in the array of keys stored in p1_keys. It reaches into p1 using that key and the square bracket syntax, because the name of the key is a variable.

    This code is isomorphic to the following Python code:

    
    p1 = {'name': 'Alice', 'gradYear': 2019, 'going': 'no'};
    p1_keys = list(p1.keys())
    for k in p1_keys:
        print(p1[k])
    
    
  2. If the method .getYear is not recommended, in what case is it being used? / What does getYear() give different answers from browser to browser, and how was this method defined?

    It was a mistake. I mention it only to help you avoid using it accidentally. It has been declared obsolete and is replaced by getFullYear

  3. Any other methods for Date objects that we might want to consider?

    There are lots, but I think I've covered all the ones you need. But feel free to look around for others that might be useful.

  4. I would like to learn more in-depth details about how the new Date(); function works.

    It creates a date object to represent a moment in time. If an argument is not supplied, that moment is the time that the function was called. If an argument is supplied, Date does its best to parse that into a specification of a date and represent that moment in time.

    The date object isn't perfect and there are proposals for replacing it, but I don't think they've been approved yet.

  5. Maybe more about console.dir?

    console.dir is great for printing objects, because it lets you dig into them a bit.

    
    var p1 = {'name': 'Alice', 'gradYear': 2019, 'going': 'no'};
    console.dir(p1);
    
    
  6. no questions / This reading felt pretty good. / The reading is clear enough. / all good!

    great!