JavaScript six notes

1. Object (Object)
- is a reference to the object in the data type JS
- object is a complex data type, a plurality of different data types can be stored in the object properties
- using a typeof inspection object returns Object
- Create Object
- Method 1:
- var obj = new new Object ();
- Second way:
- var obj = {};

- add attributes to the object
- syntax:
Object attribute name = attribute value;
Object [ "attribute name"] = properties value;

- the attribute name of the object does not have any requirements, do not need to comply with norms identifier,
but in development, as far as possible in accordance with the requirements of identifiers to write.
- The property value may be an arbitrary data type.

- Attribute reading object
- Syntax:
Object property name
objects [ "attribute name"]
- If the reading is not an object attributes, it does not complain, but a return undefined

- delete the object attributes
- Syntax :
. delete object property name
delete objects [ "attribute name"]

- use in checking the object if it contains the specified property
- syntax: in object "attribute name"
- if it contains the attribute in the object returns true
if there is no return false

- using the object literal added when creating the object directly to the subject attribute
syntax:
var obj = {
attribute name: attribute value,
the attribute name: attribute value,
the attribute name: attribute value,
the attribute name: property value
}

- basic data types and reference data types
- basic data type
String Number the Boolean Null Undefined
- reference data types
Object
- basic data types, variables are stored directly in its value.
They are independent of each other between variables and variables modify a variable does not affect other variables.
- reference data types, variables are references (memory addresses) to save the object.
If multiple variables point to the same object, then modify the properties of a variable, it will affect other variables.
- Comparison of two variables, the basic data types, is the comparison value
for comparison reference data type is an address, the same address was the same as

2 function (Function)
- is a function object, the object having common functions
- Function You can package some code, you can go when you need to call a function to execute code
- use typeof function returns a check function
- creates a function
- the function declaration
function function name ([parameter 1, parameter 2 ... shape reference N]) {
statements ...
}

- a function expression
var function name = function ([parameter 1, parameter 2 ... parameter N]) {
statements ...
};

- call the function
- syntax: function Object ([argument 1, argument 2 ... argument N]);
Fun () SUM () Alert () Number the () the parseInt ()
- when we call the function, the function code encapsulated prepared in accordance with order execution

- formal and actual parameters
- parameter: the formal parameters
- defining a function, use can be defined between one or more parameter, the parameter (), the spaced
defined parameter corresponding equivalent in function declarations but it is not a variable assignment,
shape participants assigned only when called.

- actual parameters: actual parameter
- the real function is called, the arguments can be passed (), assigned to the participants of the transmission parameter corresponding to,
the JS parser does not check the number and types of arguments of function is called, you can pass value of any data type.
If the number of arguments is greater than the parameter, the excess will not be assigned argument,
if the number is less than the parameter arguments, argument is no corresponding parameter will be assigned undefined




Say the results of each code

=========================================

var a = 123;
function fun(){
alert(a);
}
fun();

=========================================

var a = 123;
function fun(){
alert(a);
var a = 456;
}
fun();
alert(a);

=========================================

var a = 123;
function fun(){
alert(a);
a = 456;
}
fun();
alert(a);

=========================================

var a = 123;
function fun(a){
alert(a);
a = 456;
}
fun();
alert(a);

=========================================

var a = 123;
function fun(a){
alert(a);
a = 456;
}
fun(123);
alert(a);

 

Guess you like

Origin www.cnblogs.com/Jiang-jiang936098227/p/11595442.html