JavaScript is built on some very good ideas and a few very bad ideas.
Very good ideas include functions, weak typing, dynamic objects and an expressive object literal representation,
Bad ideas include a programming model based on global variables.
JavaScript functions are top-level objects based on lexical scope. Javascript was the first Lambda language to become mainstream. Compared to Java, JavaScript has more in common with Lisp and Scheme. It's Lisp dressed in C. This makes JavaScript a very powerful language.
Most programming languages now require strong typing. The idea is that strong typing allows the compiler to check for errors at compile time. The sooner we detect and fix errors, the less costly it is. Javascript is a weakly typed language, so the JavaScript compiler cannot detect type errors. It turns out that strong typing doesn't make your testing life easy; weak typing, on the other hand, is freeing. There is no need to build complex class hierarchies or force modeling.
JavaScript has a very powerful literal representation. Objects can be created simply by listing their component parts. This representation was the inspiration that led me to create the popular data interchange format - JSON.
JavaScript relies on global variables for connection. All top-level variables of all compilation units are matched into a common namespace called the global object. This is a bad thing because global variables are the devil, and in JavaScript they are fundamental.
JavaScript reserved words:
The code is as follows:
abstract boolean break byte case catch char class const continue debugger default delete do double esle enum export extends false final finally float for function goto if implements import in instanceof int interface long native new null package private protected public return short static super switch synchronized this throw throws transient true try typeof var volatile void while with
Number: 64-bit floating point number
If a numeric literal has an exponent part, then the knowledge of the literal is calculated by multiplying the part before e by 10 raised to the power of the part after e. So 100 and 1e2 are the same number.
The value NaN is a numeric value that represents the result of an operation that cannot produce a normal result. NaN is not equal to any value, including itself. You can detect NaN using the function isNaN(number).
The value Infinity represents all values greater than 1.79769313486231570e 308.
JavaScript has an object Math, which contains a set of methods that operate on numbers. The Math.floor(number) method converts a number into an integer.
Character set:
Character--16 bits (Unicode is a 16-bit character set)
JavaScript has no character type. To represent a character, simply create a string containing only one character.
The u convention allows specifying digits to represent characters. "A" === "u0041"
Strings have a length attribute. For example, "seven".length is 5.
Strings are immutable, once a string is created, it can never be changed. But it's easy to concatenate other strings with operators to get a new string. Two strings containing exactly the same characters in the same order are considered the same string.
So: 'c' 'a' 't' === 'cat'
JavaScript's simple types include numbers, strings, Boolean values (true and false), null values and undefined values. All other values are objects.
An object is a container for properties, and each other property has a name and value.
The name of the attribute can be any string including the empty string.
Attribute value can be any value except underfined value.
Objects in JavaScript are classless. It places no constraints on the names and values of new properties. Objects are suitable for collecting and managing data. Objects can include other objects, so they can be easily represented as a tree or graph structure.
JavaScript includes a prototype chain feature that allows an object to inherit the properties of another object. Used correctly it can reduce object initialization time and memory consumption.
Object literal:
Object literal provides a very convenient way to create new object values. An object literal is zero or more name/value pairs enclosed in a pair of curly braces. Object literals can appear where expressions are allowed.
var empty_object = {};
var stooge = {
"first-name":"Jerome",
"last-name":"Howard"
};
Attribute The name can be any string including hole strings. In object literals, it is not mandatory to enclose the property name in quotes if it is a legal JavaScript identifier and is not a reserved word. So enclosing "first-name" in quotes is required, but whether to enclose first_name is optional. Commas are used to separate multiple "name/value" pairs.
The value of an attribute can be obtained from any expression, including another object literal. Objects can be nested.
The code is as follows:
var flight = { airline:"Oceanic", number:815, departure: { IATA:"SYD", time:"2004-09-22 14:55", city:"Sydney" }, arrival: { IATA:"LAX", time:"2004-09-23 10:42", city:"Los Angeles" } };