Note One —— studying JavaScript: The Definitive Guide, 4th Edition
The followings are some logs after I read some chapters of JavaScript: The Definitive Guide, 4th Edition.
Chapter 1. Introducation to JavaScript
1. What's JavaScript
1)JavaScript Is Not Java : the two languages are entirely unrelated. The similarity of names is purely a marketing ploy (the language was originally called LiveScript; its name was changed to JavaScript at the last minute).
2)JavaScript Is Not Simple : JavaScript is easy to use for new and unsophisticated programmers, but it is a full-featured programming language, as complex as any and more complex than some
2.Versions of JavaScript
There are many versions of JavaScript. JavaScript 1.0, 1.1, 1.2 is provided by Netscape. JScript 1.0-5.5 is provided by Microsoft. ECMA v1-v3 is provided by ECMA which is a public organize.
3. Client-Side JavaScript
JavaScript is not only for Client-Side. When a JavaScript interpreter is embedded in a web browser, the result is client-side JavaScript. JavaScript is language like other languages, for example, c++, Java, so it can be executed in everywhere in theory. That is to say, JavaScript is a general-purpose programming language; its use is not restricted to web browsers
4. JavaScript Security
Client-side JavaScript programs cannot read local files or perform networking operations.
Chapter 2. Lexical Structure
Optional Semicolons : Simple statements in JavaScript are generally followed by semicolons (;), but you may omit the semicolon if each of your statements is placed on a separate line.
Chapter 3. DataTypes and Values
1. Primitive Data Type :
There are three primitive data types in JavaScirpt, there are Numbers, Strings, Boolean.
Primitive data types are not objects. The truth is that a corresponding object class is defined for each of the three key primitive data types. That is, besides supporting the number, string, and boolean data types, JavaScript also supports Number, String, and Boolean classes. These classes are wrappers around the primitive data types. A wrapper contains the same primitive data value, but it also defines properties and methods that can be used to manipulate that data.
2. Numbers
Special numeric constants :
Infinity : Special value to represent infinity
NaN : Special not-a-number value
Number.MAX_VALUE : Largest representable number
Number.MIN_VALUE : Smallest (closest to zero) representable number
Number.NaN : Special not-a-number value
Number.POSITIVE_INFINITY : Special value to represent infinity
Number.NEGATIVE_INFINITY : Special value to represent negative infinity
3. Strings
In some implementations of JavaScript, individual characters can be read from strings (but not written into strings) using array notation, so the earlier call to charAt( ) could also be written like this:
last_char = s[s.length - 1];
Note, however, that this syntax is not part of the ECMAScript v3 standard, is not portable, and should be avoided.
4. Functions
A function is a piece of executable code that is defined by a JavaScript program or predefined by the JavaScript implementation. There are three forms of defining functions.
1) function square(x) { return x*x; }
2) var square = function(x) { return x*x; }
3) var square = new Function("x", "return x*x;");
5. Objects
Objects in JavaScript have the ability to serve as associative arrays -- that is, they can associate arbitrary data values with arbitrary strings. That is to say, image["width"] = image.width.
you can define objects like following forms.
var point = { x:2.3, y:-1.2 };
var rectangle = { upperLeft: { x: 2, y: 2 }, lowerRight: { x: 4, y: 4} };
var square = { upperLeft: { x:point.x, y:point.y }, lowerRight: { x:(point.x + side), y:(point.y+side) }};
6. Arrays
you can define objects like following forms.
var a = new Array( );
var a = new Array(1.2, "JavaScript", true, { x:1, y:3 });
var a = [1.2, "JavaScript", true, { x:1, y:3 }];
var matrix = [[1,2,3], [4,5,6], [7,8,9]];
var base = 1024; var table = [base, base+1, base+2, base+3];
var sparseArray = [1,,,,5];
7. null and undeifned
the undefined value returned when you use either a variable that has been declared but never had a value assigned to it, or an object property that does not exist.
Although null and the undefined value are distinct, the == equality operator considers them to be equal to one another. Consider the following:
my.prop == null
This comparison is true either if the my.prop property does not exist or if it does exist but contains the value null. Since both null and the undefined value indicate an absence of value, this equality is often what we want. However, if you truly must distinguish between a null value and an undefined value, use the === identity operator or the typeof operator (see Chapter 5 for details).
Unlike null, undefined is not a reserved word in JavaScript. The ECMAScript v3 standard specifies that there is always a global variable named undefined whose initial value is the undefined value.
8. Date, Error, Regular Expression
you can use like the following:
var xmas = new Date(2000, 11, 25);
/^HTML/
/[1-9][0-9]*/
/\bjavascript\b/i