Tuesday, February 1, 2011

Week 1 Assignment

Questions and Answers for reflection:

1.
The alliance of Netscape and Sun Microsystems did not use Java in the browser, because it was not suitable for that purpose. Why do you think Java was not suitable to be embedded in a browser?

Java is a compiled programming language whereas Javascript is interpretive, meaning Javascript can be directly read as machine language during run time, decreasing the resources required to run Javascript in a browser. The fact that it executes client-side makes it ideal for web-based applications since a lesser strain is put on the server machine when many users are trying to access the content simultaneously.

2.
When parsing a String into a number using the parseInt() method, we are advised to always provide the radix. Why is it so strongly recommended?

The parseint() method searches for a numeric value in the first position in the string and converts this and subsequent numeric characters into an integer-type value (returns NaN if the leading character not a number). It is recommended to specify the radix because an unexpected basis may be used depending on the contents of the string.


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

A type specifies the category of data that a variable is expected to contain and this dictates the way in which the variable interacts with functions and operators. Assigning a data type also restricts variables to their valid ranges to prevent unexpected behaviour.

4.
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?

Decimal numbers are represented using the floating point data type, which cannot precisely represent all real numbers since they consist of a summation of base-2 fractions. Thus, numeric operations should be rounded/truncated to integers if exact answers are needed. These rounding errors also have great effects when multiplied by large numbers.

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

To minimize the use of brackets, mathematical operations in Javascript follow the standard precedence rule for math expressions. Thus:
115 * 4 - 4 + 88 / 2
= 460 - 4 + 44
= 500

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

The typeof returns a string indicating the type of the argument. In this case, any number of typeof functions called within the argument of typeof will always return a string since the typeof call lowest in the hierarchy will always return a string.

Tuesday, January 11, 2011

Reflections on Javascript Basics - 1

Well, today I start my long and fruitful journey on the path of Javascript by (hopefully) enrolling in this P2PU course.....to be honest, I'm a little freaked out by the fact that I need to complete an assignment just to register for the course.

The required viewing looks like it was filmed a few years back (Blair Witch Project? Really??) but served its purpose of giving a brief background to and introducing the key concepts of the language. I guess that's all that matters. This is supposed to be a course, after all.

Based on this video, it seems that Javascript was designed with a user-friendly focus. This is great for noobies like me. The guard and default operators are clean and straightforward, the loose typing gives greater flexibility, and I like how "falsey" and "truthy" values are matched to boolean true and false. Pretty slick stuff. Oh, the overloaded "+" operator example......gotta be careful with that but at least using + is usually intuitive and tidies up the appearance of the code.

I'd be interested in seeing where this all leads. Aside from improving my web savvy, I also promised a friend to create a website for her may-or-may-not-be-realized English school for children in Asia. Aside from handling registration, I think delivering courseware online could be neat feature in this website.

Anyway, this is all daydreaming for now.....