Week 1 - JavaScript

Week 1 - JavaScript


  1. What is a type, and why do you think types are useful in writing programs?
  2. Why do we lose precision when performing operations with decimal numbers in JavaScript? Can you think of a few implications of why this would be a problem?
  3. Do you understand why the following operation produces the given result 115 * 4 - 4 + 88 / 2 = 500
  4. What is the use of a backslash character in a String?
  5. What does typeof 4.5 do, and why does typeof (typeof 4.5) return "string" ?
  6. The author writes When your browser loads a page, it creates a new environment and attaches these standard values to it. The variables created and modified by programs on that page survive until the browser goes to a new page.. Without searching on the net, can you think of some variables that might be created in the browsers environment when it loads a page with JavaScript in it?


  1. A type is like a role that an actor plays in a movie, it is responsible for letting JavaScript know exactly what we want it to do with the data that we are providing to it. (The different types in JS are: Number, String, Boolean, Object, null and undefined).
  2. We lose precision because of the fact that JavaScript dedicates only 64bits to Numbers and 11 of those goes to locating the decimal dot within the number.
  3. Yes, JavaScript follows the traditional mathematical model which gives multiplication (*) and division (/) authority over any other operators. The operation ends up being : 115 * 4 = 460. 88 / 2 = 44. 460 - 4 + 44 = 500
  4. It is used to indicate that "the character after it has a special meaning" (string = "Go to\nnew line") or to cancel out quotes (string = "Test\'s shall be overdue").
  5. typeof 4.5 returns the type of 4.5, which would be Numbers. typeof (typeof 4.5) returns "string" because ultimately it is trying to determine the type of (typeof 4.5) which is indeed a string.
  6. I would think they would variables such as resolution and locale (language)

Exercises 2.1 - 2.6 from chapter 2

Exercises 3.1 - 3.2 from chapter 3

Show Comments