JS is an object-oriented language
- Packaging
- Inherited
- Polymorphic
- Clustered (has the ability to reference other objects in the object)
The majority of situations in JS use do not require object-oriented design, in many cases the use of objects that have been designed and prepared, based on the language of the object.
Use of JS (introduced)
- Write directly in the script tag in JSP, HTML
- Introducing in the script tag
Attention:
-
- The script tag location is arbitrary. But the higher the position, the earlier the execution. ( important )
- JS External File The recommended extension is. js. But in fact any suffix name can be.
- Using the script tag to introduce an external file, you should not write the JS code in the script tag.
The basic syntax of JS
Variable declarations use Var, where variables are case-sensitive STR and STR are not the same variables. Strings can be wrapped using double quotation marks ("") or single quotation marks (""). The type of the variable can be changed at any time. The naming convention is the Hungarian notation.
var str = 1; var str = "Hello"; There's no difference between the two.
- End of line uses ";" as the ending symbol for a line. (There can be no ";", with a line break (carriage return) as the end of a line.) (Not recommended)
- There are two types of annotations in JS, multiple lines
Single-line Comment "//" Multiline comment "/* */"
Type of JS
JS is divided into two types of
-
- Raw data type
- Object data type
Basic data types in Java have a byte short int long float double Boolean char
JS in the original data type has number (numeric, floating point type, integer type)
String (JS language breakthrough, no char type.)
Boolean
Null (used to indicate a placeholder for the reference data type.) is usually an artificial assignment. var person = null;
Undefined (the value derived from NULL is when we declare a variable,)
1. If the variable is not initialized, the system will default to the value undefined
2. There is no return value in the function, then the default return undefined
Primitive data Type qualifier:
typeof is used to determine which primitive type a variable is.
Null returns object, which is a bug in JS, which is considered appropriate. So the bug was preserved.
The statement in JS
There is a loop in Java: for while-do Do-while
There is a judgment: if switch
The statement in JS is exactly the same as in Java!
Special: The enhanced for loop in Java is not in JS.
JS has a for (Var xx in xx) statement. Used to traverse the properties of an object.
JS in operator
Unary operators
unary addition, subtraction
var a = +1;
var B =-1;
Advanced applications in JS.
var c = + "1"; Making type conversions
var d = + "abc"; Conversion failed, returning the special value NaN in number.
Boolean operator! && | |
Automatic type conversion in JS. Transformation Law (emphasis)
String ==> "" is converted to false and the others are true;
Number ==> except for nan,+0 and-0. All others are converted to true.
Null ==> False
Undefined ==> false
Nan Features:
Any Boolean operation that Nan participates in returns a value of false. except = =, because undefined is null derived, so alert (undefined = = null);//True
Comparison operators
alert (11>3); True
When an operator ends with a number, and one end is another, the other type is automatically converted to the number type
Alert ("one" >3); True
Alert (11> "3"); True
When a string is compared, the rule is: Compare the first character ASC code. If same, compare 2nd bit ...
Alert ("One" > "3"); False
Alert ("One" > "1"); True
Alert ("abc" >11); False
Equal sex operator = = = = = = = = = =
All equals: = = = The type is included when comparing.
Objects in the ECMAScript
- Object is a superclass of all objects.
function objects and the creation of function
- var fun1 = new Function ("A", "B", "Alert (a+b);");
- var fun2 = function (A, b) {alert (a+b);}
- function Fun3 (A, b) {alert (A+B)}
- Call to function
- The invocation of a function in JS only looks at the function name. Built-in object arguments when called, arguments represents the actual argument list during function run.
Arguments.length Number of actual parameters
ARGUMENTS[0] the first parameter.
Application: Arguments implements overloading of functions.
- Return of function
1. If the function does not display the specified return value, then the function return value is undefined.
2. Use the return keyword to return content
3. The return keyword, in JS can also be used as the end method to run the function.
4. Application of the void operator.
The classification of objects in ECMAScript
- Local objects
Built-in objects do not need to create an instance. Use Global Math directly
Host Object DOM BOM two parts.
3 wrapper objects in ECMAScript.
String number Boolean
Pseudo-Object: String Number Boolean These 3 primitive types can be thought of as pseudo-objects and can invoke the methods and properties of the wrapper object directly.
String object property Length
Important method
IndexOf
LastIndexOf
CharAt
Alert (Str1.charat (0)); A
charCodeAt returns the ASC code for the character that is located
Alert (str1.charcodeat (0)); 97
SubString
Alert (str1.substring (0, 1)); A
Slice supports negative numbers. Go from right to left.
Alert (Str1.slice (0,-1)); A
The method of combining with the regular
Split
Replace
Match
Search
Global Object
JS getting acquainted