Quiz
- Why does javascript have a unique object type for dates?
I dunno. Good question; I just don't know the answer.
- This creates a variable called dateObj2
, how is it different from ""Object""? I'm a bit confused by how this resembles Java but not exactly the same. Why is ""Date"" an object but not dateObj2?
When we're invoking methods e.g. dateObj2.getFullYear() , does it mean that we call methods on the variable dateObj2?
Object
is like a Java class. In fact it is exactly like theObject
class in Java: it is the ancestor of all classes. See Java Object ClassThe value of
dateObj2
is an object. It's a particular date, which is different from theObject
class.The value of
Date
is a class.Yes, we can call Date methods on
dateObj2
- weekdays.splice(2,1,"Odin's Day"); what does the one indicate ? Odin's day replaces third element, but what does 1 mean?
The 1 is the deleteCount: we are deleting one element. See: MDN Array Splice
- Can both String() and toFixed be used in turn a number into string? What's the difference between them? Thank you!
Yes.
toFixed
has more features, like choosing a radix. - I'm confused about question 4--aren't person1.age and person1[age] equivalent?
Good question! No, they aren't. Because in
person1[age]
,age
is a variable, while inperson1.age
is it a literal.Consider the following code:
- In what case we would not know the names of the properties? / In the Unknown Properties section of the reading, you say "The expression p1[k] means to look up a key in the dictionary in p1 where the name of the key is in the variable k", but where is the variable k? Was it ever initialized? Just not sure where the k is coming from.
Let's play with the JS code in the browser.
- when to use unknown properties
When the property you need to access is in a variable instead of known in advance. Here's another example:
- How would you change values in a dictionary in a loop format for eg if you had to add the string "str' to all values against their keys. Would you still use for each method and just create a new method and invoke that inside another method you create for the updated dictionary. Sorry if this is confusing, Im trying to think of how we navigate such a problem in python and if javascript handles it similarly. Thankyou!
Suppose we wanted to add an exclamation point to all the capitals:
- Just wanna say hi and thanks
Hi!