Monday 31 January 2011

Week 1 Questions for Reflection

1. What is a type, and why do you think types are useful in writing programs? 

Type separates data values and determine what they can do and what the programmer can do to it. There are six basic types in Javascript: Numbers, strings, booleans, objects, functions and undefined values.

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?

Some decimal numbers are only an approximation when expressed with Javascript. Javascript’s Number Type only has 64 bit floating point and therefore can only approximate decimal numbers that have a infinite decimal value, such as pi or the value of 10 divided by 3. (10.3333333)

A problem that could arise is with money. The imprecision with decimals can lead to accounting errors.

3. Do you understand why the following operation produces the given result 115 * 4 - 4 + 88 / 2 = 500

With the about operation, the multiplication and the division is performed first, so we get
460 - 4 + 44 = 500 

 4. What is the use of a backslash character in a String?

The back slash character in a string tells the string to treat what immediately following the backslash character to be a special character. 

For example:
\n is the same as new line
\t means tab
\\ means just the character backslash \

 
What does typeof 4.5 do, and why does typeof (typeof 4.5) return "string" ?

The typeof operator returns the Type of the value given to it.

e.g. typeof 4.5 returns the value of  Number

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?

Some of the variables could be standard mathematical constants such as pi or internal set variables used by the program, such as the boolean values of certain internal variables and variables used in the definition of various functions.

No comments:

Post a Comment