Saturday, January 15, 2011

Notes about JavaScript Basics - 1 video

Douglas Crockford ‘s video about Javascript basics -1 shows the background and evolution of  what  Javascript is today: a very popular,  platform independent, object based, client and server side, complete programming language, which uses a C type of  syntax, from the functional languages family, the result of  Sun and Netscape collaboration.

Javascript distinguishes itself from the other languages by the following key concepts:

1.    Load and go delivery: programs are delivered to the execution site as text.
2.    Loose typing: even it’s against the today’s “strong typing” main stream it improves the processing
power and makes the coding process easier.
3.    Objects as general containers: it unifies objects and hashtables creating very dynamic objects.
4.    Prototypal inheritance: objects inherit directed from other objects, there are no classes.
5.    Lambda: use of classes as first class objects.
6.    Linkage through global variable:  defines a global namespace that raises security and reliability
problems.

Javascript has a small number of values:

1.    Number:  there is only one number type, represented as 64 bit floating point and it does not map well

the common understanding of arithmetic.
NaN: Not a Number – a special value, the result of undefined or erroneous operations.
Number function: Number(value) – similar to + prefix operator, converts a value to a number.
parseInt function: parseInt(value, radix) .
Math object: copied Java’s Math class.
2.    String: represented by 16 bit charactes, using UCS-2 encoding, immutable.
String function: String(value) – converts value to a string.
Strings are objects and have methods (like length).
3.    Boolean: true or false.
Boolean function: Boolean(value) – deals with truthy and falsy concepts.
4.    null: a value that isn’t anything.
5.    undefined: default value for variables and parameters, the value of missing members in objects.
6.    Objects: new Object() produces an empty container of name/value pairs

The video describes also the characteristics of:
-    Identifiers
-    Reserved words
-    Comments
-    Operators: they are similar to those in C languages with a few nuances

My JavaScript solution for the task 2 stated in the prerequisite is:

<html>
<head>
<script type="text/javascript">
function sum(a,b)
{
return a+b;
}function message()
{
alert("2+2=" + sum(2,2));
}
</script>
</head>
<body onload="message()">
</body>
</html>

No comments:

Post a Comment