2 JavaScript in HTML
deferred scripts
- the purpose of defer is to indicate that a script won’t be changing the structure of the page as it executes.
- Setting the defer attribute on a
Asynchronous Scripts
- Also similar to defer, async applies only to external scripts and signals the browser to begin downloading the file immediately. Unlike defer, scripts marked as async are not guarantedd to execute in the order in which th
- ey they are specified.
- an async scripts is to indicate that the page need not wait for the script to be downloaded and executed before continuing to load, and it also need not wait for another script to load an execute before it can do the same. … not modify the DOM as they are loading.
SUMMARY
- you can defer a script’s execution until after the document has rendered by using the defer attribute.
- .. a script need not wait for other scripts and not block the document rendering by using the async attribute. Asynchronous scripts are not guaranteed to execute in the order in which they occur in the page.
3 Language Basics
DATA TYPES
- five simple data types(primitive types):Undefined, Null, Boolean, Number, and String。
The Null Type
- undefined is a derivative(衍生物) of null, null == undefined //true
The Boolean Type
These values are distinct from numeric values, so true is not equal to 1, and false is not equal to 0.
1==true, 0==false
The Object type
each object instance has the following properties and methods:
- constructor:the function that was used to create the object.
- hasOwnProperty(propertyName)
- isPrototypeOf(object)
- propertyIsEnumerable(propertyName)
- toLocaleString()
- toString()
- valueOf()
Understanding Arguments
- …arguments in ECMAScript are represented as an array internally. … In fact, there actually is an arguments object …
- the arguments object acts like an array(though it isn’t an instance of Array) …
function doAdd(num1,num2){
arguments[1]=10;
alert( arguments[0] + num2 );
}
this version of doAdd overwrites the second argument with a value of 10. Because values in the arguments object are automatically reflected by the corresponding named arguments, the change to arguments[1] also changes the value of num2, so both have a value of 10. This doesn’t mean that both access the same memory space, though; their memory spaces are separate but happen to be kept in sync. This effect goes only one way: changing the named argument doen not result in a change to the corresponding value in arugments. Another thing to keep in mind : if only one argument is passed in ,then setting arguments[1] to a value will not be reflected by the named argument. This is because the length of the arguments object is set based on the number of arguments passed in , not the number of named arguments listed for the function.
4 Variables ,Scope, and Memory
PRIMITIVE AND REFERENCE VALUES
Copying Values
When a reference value is assigned from one variable to another, the value stored on the variable object is alse copied into the location for the new variable. The difference is that this value is actually a pointer to an object stored on the heap.
Determining Type
typeof
result = variable instanceof construtor