JS Learning Note 1

Source: Internet
Author: User
Tags sorts

Chapter II, lexical structure
1.javascript program is written in Unicode character set, 2 bytes
2. Case sensitive, which means JavaScript needs to be case sensitive
3.JavaScript ignores spaces, tabs, and line breaks between tokens in the program.
4. In JavaScript, you can omit semicolons if the statements are placed in separate rows. However, it is not recommended to omit semicolons.
Although JavaScript is theoretically allowed to place line breaks between any of the two tokens, JavaScript is actually automatically inserted into the semicolon, which makes it easy to notice exceptions.


5.JavaScript Comments://And/* */.
6. Direct variable: The data value that is displayed directly in the program. such as: "Hellworld", etc.
7. Marker: The first character must be a letter, an underscore or a dollar sign, followed by a letter, a number, an underscore, or a dollar character
8.JavaScript retention cannot be used as a marker


























Chapter III, data types and values
1.JavaScript allows the use of 3 basic data types, numbers, text strings, and Booleans, and also supports two small data types, null (empty) and undefined (undefined).
Composite data Type objects (object), functions and arrays are also supported
2. Numeric number is a basic data type that does not differentiate between integer and floating-point values, and JavaScript uses the 64-bit floating-point format defined by the IEEE754 standard to represent numbers.
3.16 binary means start with 0x or 0X, and the direct amount of the 8 binary begins with the number 0.
String literals in 4.JavaScript are contained in single or double quotation marks. It does not have a character data type such as char, and to represent a character, a string of length 1 must be used.
5. String Direct constants must be written on one line, and if they are placed in 2 rows, they may be truncated.
6.html also uses single or double quotation marks to delimit strings, so when using JavaScript and HTML at the same time, it is best to use JavaScript as a reference and another way of referencing HTML.
7. Determine the length of the string using the Long property. "Hello". length
8. Converts a number to a string, and the number is automatically converted to a string when needed. either use Var number1=string (number) or use Var number2=number.tostring ().
9. Convert a string to a number: When a string is used in a digital environment, it is also automatically converted to a number Eg:var product= ' 21 ' * ' 2 ';
You can also subtract a string by 0 to convert it to a number eg: ' 32 '-0; note that adding 0 back to a string value results in a string connection instead of a conversion.
var num=number (string_value) can also convert a string to a number. You can also use the parseint or parsefloat function
10. If a Boolean value is used in a numeric environment, true is converted to the number 1, and false is converted to the number 0. If a Boolean value is used in a string environment, true is converted to
' True ', while false converts to ' false '; If a number is used in a place that is supposed to be a Boolean value, then if the number is 0 or Nan, it will be converted to false, otherwise it will be converted to true.
If the string is used where the Boolean value should be used, then the empty string is converted to false, otherwise it will be changed to true. Null values or values that are defined are also converted to false, and any non-empty objects, arrays, or functions are converted to true.

11. Functions: Function name (argument list) {function body} or Use function Direct amount to define it var variable name =function (argument list) {function Body}
12. The object is a collection of named data, the object name. Property names to use to access the object's properties
13. If a function value is stored in a property of an object, then that function is often called a method, and the property name becomes the method name. The method to invoke an object is to use the "." Syntax converts a function value from an object
Extract it, and then use the "()" syntax to invoke that function.
14. Create object: Var o=new object (); var now=new Date (); Once you have created your own object, you can design and use its properties as you wish:
var point=new Object ();
point.x=2.3;
point.y=-4;
point.s= "Hello World";
15. Object Direct Volume: Creates an object and defines its properties. The direct amount of the object is made up of a list of attribute/value pairs separated by colons, separated by commas, and the entire list enclosed in curly braces.
var point={x:3.2,y:-4,s: ' Hellow '};
16. Conversion of objects: When a non-empty object is used in a Boolean environment, it is converted to true. When an object is used in a string environment, the JavaScript object calls the ToString method and uses the value of the string returned by the function.
When an object is used in a digital environment, JavaScript first calls the object's ValueOf method, and if the method returns a value of the base type, the value is used. However, in most cases, the valueof method
Returns the object itself. In this case, JavaScript first uses the Tostirng method to convert the object to a string, and then attempts to convert the string to a number.

17. Arrays can hold any type of JavaScript data, including references to other arrays, objects, or functions.
18. Creation of the array: var a=new array ();
a[0]=2;
a[1]= ' Hellow ';
A[4]={x:1,y:2};
or use Var a=new Array (1.2, ' Hello ', true,{x:2,y:5});
Creates an array of the specified length: var a=new array (10); Value not initialized
19. Array Direct constants: JavaScript defines the direct constant syntax for creating and initializing arrays. An array of direct constants (or array initializers) is a closed in square brackets in the German sequence, in which the German elements are separated by commas.
The values in parentheses are assigned to the array element in turn, and the subscript value starts at 0. eg
var a=[1.2, ' Hello ', true,{x:1,y:4}];
The 20.javascript keyword NULL is a special value that represents no value. Null is often considered to be a special value of the object type, that is, a value that represents no object. Null is a unique value that differs from all other values.
If the value of a variable is null, then it indicates that its value is not a valid object, array, number, String, and Boolean value. When NULL is used for a Boolean environment, it is converted to false. When it is used in a digital environment, it is converted to 0.
When it is used in a string environment, it is converted to ' null '
21.javascript also has a special value, undefined, when you use a variable that is not declared, or when you use a variable that has been declared but has not been assigned a value
, or if you are using an object property that does not exist, this value is returned. Note that this special undefined value is different from null. Although the undefied and null values are different,
But the = = operator considers the two equal. To differentiate between null and undefined, you can use the = = = or the typeof operator. When a defined value is used for a Boolean environment, it is converted to false;
When it is used in a digital environment, it is converted to Nan. When it is used in a string environment, it is converted to ' undefined '
22.
23.
24.
25.
26.
27.
28.
29.










Fourth Chapter, variable
1. Declaration of variables:
var variable name, or var variable name = initial value, or var variable name 1, variable name 2, traverse name 3;
If a variable is not given an initial value using the var statement, the variable is declared, but the initial value is undefined before it is saved to a value.
Declaring the same variable multiple times with the Var statement is not only legal, but it does not cause any errors. If a duplicate declaration has an initial value, then it assumes the role of an assignment statement.
Note: If you attempt to assign a value to a variable that is not declared with Var, javascript implicitly declares the variable. When it is important to note that implicitly declared variables are always created as global variables, even if the variable is used only within a function body. Local variables are only in one function
To prevent the creation of global variables (or the use of existing global variables) when creating local variables, you must use the VAR statement inside the body of the function. Whether it is a global variable or a local variable, it is best to create it using the VAR statement.
2. Variable has scope
3. In JavaScript, all variables declared in a function are defined in the entire function, regardless of where they are declared.
Although local variables are defined throughout the body of the function, they are not initialized until the VAR statement is executed (before the declaration).
4. Numeric, Boolean, NULL, and undefined are basic types. objects, arrays, and functions belong to reference types. The base type has a fixed size in memory.
5. When the JavaScript interpreter starts running, one of the first things it does is create a global object before executing any JavaScript code. The properties of this object are the global variables of the JavaScript program.
When declaring a JavaScript global variable, what is actually done is to define a property of that global object. A local variable is a special property of the calling object.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21st.
22.
23.
24.
25.
26.
27.
28.
























Fifth chapter, Expressions and operators
1.== operator (equality operator) and = = = operator (equivalent operator)
2. Inequality operator! = And not equal operators! ==
The 3.in operator requires that its left operand be a string, or it can be converted to a string, and the right operand is an object or an array. It returns true if the value to the left of the operator is a property name for the object to the right.
The 4.instanceof operator requires that its left operand be an object, and the operand on the right is the name of the object class. If the object to the left of the operator is an instance of the right class, it
Returns TRUE, otherwise false is returned.
5. Although all the numbers in Jacascript are floating-point, the bitwise operator requires that its numeric operation be integer. They manipulate the integer notation of the 32-bit notation used for these integer operands, rather than the equivalent floating-point notation.
6. Bitwise operator &,|,!, ^,~,<<,>>
7.typeof is a unary operator that can be any type before it is placed in an operand. Its return value is a string that describes the type of the operand.
The 8.new operator is used to create a new object and call the constructor to initialize it.
The 9.delete operator is a unary operator that removes the attributes, array elements, or variables of the object that the operand refers to. If the delete operation succeeds it will return true if the operand cannot be deleted, it will return false.
10.void is a unary operator that can appear before any type of operand. The use of this operator is special, it always discards the value of the operand, and then returns undefined.
11. The comma operator (,), the comma Operation Mr. Foo evaluates its left argument, computes its right argument, and then returns to the right argument.
12.
13.
14.
15.
16.
17.
















Sixth Chapter, statement
The match case expression in 1.switch is determined by the = = = equivalent operator, not by the = = equality operator, so the expression must match without a type conversion.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21st.
22.
23.
24.
25.
26.
27.
28.
29.








































Seventh chapter, Objects and arrays
1. The simplest way to create an object is to include an object direct constant in the JavaScript code. An object's direct constant is a comma-delimited list of property names and values of pairs, enclosed in a curly brace, each of which can be a JavaScript marker or a string.
Each property value can be a constant or any JavaScript expression.
Var Empty={};//an object with no properties.
var point={x:0,y:0};
var circle={x:point.x,y:point.y+1,radius:2};
var homer={
' Name ': ' Homer Simpson ',
' Age ': 23,
' Married ': true
};
An object's direct constant is an expression that creates and initializes a new, different object each time it is evaluated. This means that if a single object directly constants
It can create many new objects when it appears in the loop body of a function that is called repeatedly.
The new operator can create a specific class of objects. After new, call a constructor that initializes the properties of the object.
var a=new Array ();
var d=new Date ();
var r=new RegExp (' JavaScript ', ' I ');

2. Properties of an object: typically use "." operator to access the value of an object's properties. The value on the left side of the. Operator is the object whose properties you want to access. Typically, it contains only the variable name of the object's reference, but it can be any
The result is a JavaScript expression for the object. Located in the '. ' The value to the right of the operator should be the property name, which must be an identifier and cannot be a string or an expression.
3. Check the existence of attributes: The in operator can be used to test the existence of a property. The left side of the operator should be the name of the property (in string form), and the right side of the operator should be the object to be tested.
4. Delete attribute: Delete Object name. property name;
5. An object that is an associative array
Object.property equivalent to object[' property '];
Properties and methods for 6.object
Constructor property
ToString () method
The toLocaleString () method returns a localized string for the object
ValueOf () method It is a method that is called when JavaScript needs to convert an object to a basic data type, that is, a number instead of a string.
The hasOwnProperty () method returns True if the object locally defines a non-inherited property with the name specified by a separate string argument. Otherwise, false is returned.
The Propertylsenumerable () method, if the object defines a non-inherited property with the name specified by a separate string argument, and if the property
Can be enumerated in a for/in loop, the method returns True, otherwise false is returned. Note: All user-defined properties of an object can be enumerated, not enumerated
Properties are usually inherited.
The isPrototypeOf () method returns True if the object to which it belongs is the prototype object of the parameter. Otherwise it will return false
7. Create an array:
The simplest way to create an array is to use the array direct constant, which is just a list of array elements separated by commas in parentheses:
var empty=[];//an array with no elements
var primes=[2,3,4,5,];
var misc=[1.1,1,true, ' a '];
var a=new Array ();
var a=new Array (5,4,3,2,1,, ' test ', true);
var a=new Array (10);

8. Note that the subscript of an array is greater than or equal to 0 and less than 2 of the 32-square-1 integer, if the number used is too large, or if a negative value is used, the float (or Boolean, object, and other values), JavaScript converts it to a string, using the generated
String as the name of the object property, not as an array subscript.
9. Properties and methods of the array:
Join () method, the method join () converts all elements of an array into strings, and then joins them together. You can specify a separator for the transformation.
Reverse () Reverses the order of the array elements and returns the inverted array.
Sort () sorts the array elements on the original array, returning the sorted arrays. If you call sort () and do not pass the parameter to it, it sorts the array elements in alphabetical order. If the array has undefined elements, these elements
will be placed at the end of the array.
Concat () can create and return an array that contains the elements of the original array that called Concat, followed by the parameters of the concat ().
The slice () method returns a fragment of the specified array, or a sub-array.
The splice () method is a common method for inserting or deleting an array element. You can remove elements from an array, insert new elements into an array, or perform two operations at the same time.
The push and pop methods allow us to use arrays as we do with stacks.
The behavior and push of the unshift and shift methods are very similar to pop, except that they are insertions and deletions of elements in the head of the array.
The ToString method converts each element of an array to a string
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21st.
22.
23.
24.
25.
26.
27.
28.
29.












































Eighth chapter, function
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21st.
22.
23.
24.
25.
26.
27.
28.
29.




































Nineth, classes, constructors and prototypes
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21st.
22.
23.
24.
25.
26.
27.
28.
29.


































Tenth chapter, modules and namespaces
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21st.
22.
23.
24.
25.
26.
27.
28.
29.
























11th chapter, pattern matching using regular expressions
1. The regular expression direct constant is defined as a character that is contained between a pair of slashes (/). Or use the new RegExp () constructor.

2. Character class/[abc]/
\s matches whitespace, tabs, and other Unicode whitespace characters
\s characters that match non-Unicode whitespace characters
{N,m} matches the previous item at least n times, but cannot exceed m times
{N,} matches the previous item n times, or more
{n} matches the previous item exactly n times
? Matches the previous item 0 or one time, which means the previous item is optional. Equivalent to {0,1}
+ Match the previous item 1 or more times. Equivalent to {1,}
* Match the previous item 0 or more times. Equivalent to {0,}
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21st.
22.
23.
24.
25.
26.
27.
28.
29.





















































The 12th chapter, script session Java
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21st.
22.
23.
24.
25.
26.
27.
28.
29.
































13th Chapter
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21st.
22.
23.
24.
25.
26.
27.
28.
29.











































































































































































































































































































































































Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.