Sunday, January 30, 2011

Week1

  1. What is a type, and why do you think types are useful in writing programs?
    A type specifies the type of a specifically declared variable/string/array/object
    It refers to a specific value, number/boolean/string/array/object a user/program can define and manipulate in a program.

  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?
    In javaScript numbers are stored as 64bits. Some of those bits are reserved based on the numerical value, which means there are only some 50bits available to encode a numerical value.
    Precission is lost for decimal values if the complete decimal value cannot be stored in the available bits.
    For example the number of PI has an infinite number of decimal values and so the complete number cannot be stored in the available bits and so some precision is lost.

  3. Do you understand why the following operation produces the given result 115 * 4 - 4 + 88 / 2 = 500
    javaScript, like many other programming languages, support order of precedence, ie. the order of which mathematical operations are performed.
    In javaScript we follow the order:
      "PEMDAS", → Parentheses, Exponents, Multiplication and Division, and Addition and Subtraction
      (((115*4) – 4) + (88/2)) = 500
  1. What is the use of a backslash character in a String?
    A backslash in a string indicates that the character following the backslash has a special meaning. Special meaning of characters can be looked up from the ASCII table.

  2. What does typeof 4.5 do, and why does typeof (typeof 4.5) return "string" ?
    typeof Specifies the type if the operand passed to the operator
    typeof 4.5 Returns the type of the variable → number
    typeof(typeof(4.5) Returns the type of the returned operand type
    typeof(typeof(4.5) → number) → string

  3. 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?
          I assume that everything that has been defined between the tags <script> …... </script> →                    javaScript are created when the object window is loaded. So far, in our small programs we have  
              used variables like var, used methods like promp/write/functions/etc.
             All this is loaded when the window loads.

Coding Assignments Week1
http://jsfiddle.net/swissrunner66/Lnc26/9/

No comments:

Post a Comment