Final Study Guide

Here is a representative list of questions for the final. You should be able to answer these questions or questions similar to them.

  1. Explain the differences between local variables, parameters, the special variable this, and global variables.

  2. Which of the following are valid ways of accessing the element at the entry with index 1 in an array a?

    1. a.1
    2. a."1"
    3. a1
    4. a[1]
    5. a["1"]
    6. a(1)
    7. a("1")
  3. Which of the following will the expression Object.create({ a: 2 }) create?

    1. An object with a property a.
    2. An object whose prototype has a property a.
    3. An empty object with empty prototype.
    4. Nothing useful, it is not a valid expression.
  4. Create an object obj that has an enumerable property b but for which the expression obj.hasOwnProperty("b") returns false. What would then be two valid ways to test that obj does indeed have a property b?

  5. Which of the following can be possible scopes for local variables (distinguish between variables declared via var and those declared via let or const)?

    1. Function bodies
    2. Any sets of curly braces
    3. the bodies of for loops
  6. Using ES6 templates, write a function that takes as a parameter someone’s name and returns a string that greets them.

  7. What do template libraries like Handlebars bring to us that can’t easily be done with ES6 templates?

  8. What would be the code that would allow us to add to an object o a property a whose value is 20, it cannot be changed, and it appears when we look at the object’s keys via Object.keys?

  9. Similar to the Person class that appears at the bottom of the object properties notes, write a Point class with the following behaviors:

  10. The following code creates an adder class, and uses it:

    You also have a module of your own, which gets loaded inbetween the Adder module and the module that uses the Adder module. Describe what changes you would make to achieve each of the following: - The add method always adds the number 42 in the numbers array. - The computeSum method always returns 42 as its result. - The push method does NOT add the elements in the array (or any other array for that matter). - The add method does it job normally, but the numbers are also added to an array defined in your module.

  11. We discussed three different graphics technologies for the web. What are they? What are the pros and cons of each?

  12. Write SVG.js code that would produce the following:

  13. Describe what Javascript Promises are, what states a promise can be in, and how to use a promise to handle an asynchronous event. Use promises to create a delay(milliseconds) function that can be used to trigger actions after a specific time.

  14. What is the same-origin policy? Why is it in place? Why does it not affect script tags?

  15. Describe how CORS works, being clear about all the actors involved.

  16. Describe how the keywords async and await behave, and what they allow us to do.

  17. What is the XMLHttpRequest object used for? How is it set up to use so that we do not have to block everything while waiting for a reply?