1. Operator
Operators are a series of symbols that complete operations, and they have seven categories:
Assignment operator (=,+=,-=,*=,/=,%=,<<=,>>=,|=,&=), arithmetic operator (+,-,*,/,++,-,%), comparison operator (>,<,<=,>=,==,==,!=,!==), logical operator (||,&&,!), conditional operator (?:), displacement operator (|,&,<<,>>,~,^) and string operator (+).
Many people may not know what "===" is.
Here, I will explain to you that in javascript, "==" is the equivalent operator.
Comparison rules for equivalent operators:
When the types of two operands are different: convert them to the same type
1) A number is compared with a string. After the string is converted into a number, compare it.
2) Convert true to 1, convert false to 0, and compare.
3) An object, array, function and a number or string are converted into values of the original type and then compared. (Use valueOf first, if not, use toString)
4) Other types of combinations are not magnitude.
If you want the two arithmetic numbers to be the same, or after converting them to the same type:
1) 2 strings: The characters at the same position are equal, and the two strings are the same.
2) 2 numbers: If 2 numbers are the same, it is the same. If one is NaN, or both are NaN, it is not the same.
3) If both are true, or both are false, then the same is true.
4) If the two references are the same object, function, and array, they are equal. If the references are not the same object, function, or array, they are different, even if the two objects, functions, and arrays can be converted into completely equal original values.
5) 2 nulls, or 2 are all undefined, then they are equal.
"===" is an all-same operator. The all-same operator follows the comparison rules of the equivalent operator, but it does not type convert the operands. When the types of the two operands are different, it returns false; only when the types of the two operands are the same, the comparison rules of the equivalent operator are followed for comparison.
For example: null==undefined will return true, but null===undefined will return false!
2. Expressions
The combination of operators and operands is called expressions, which are usually divided into four categories: assignment expressions, arithmetic expressions, boolean expressions and string expressions.
3. Sentences
A Javascript program is composed of several statements, and the statement is a directive for writing the program. Javascript provides complete basic programming statements, which are:
Assignment statement, switch selection statement, while loop statement, for loop statement, for each loop statement, do while loop statement, break loop abort statement, continue loop interrupt statement, with statement, try...catch statement,
if statement (if..else, if...else if ...), let statement.
4. Function
A function is a named statement segment, which can be referenced and executed as a whole. The following points should be paid attention to when using functions:
1) The function is defined by the keyword function (can also be constructed by the Function constructor).
2) Functions defined with the function keyword can be called at any location within a scope (including before the statement that defines the function); while those defined with the var keyword must be defined before they can be called.
3) The function name is the name referenced when calling a function. It is case sensitive and you cannot write the wrong function name when calling a function.
4) The parameter represents the value passed to the function for use or operation. It can be a constant, a variable, or a function. All parameters can be accessed within the function through the arguments object (the arguments object is a pseudo array, and the property callee references the called function).
5) The return statement is used to return the value of the expression.
6) The yield statement throws an expression and interrupts the function execution until the next call is next.
Generally, functions are in the following format:
The code copy is as follows: function myFunction(params){
//Execution statement
}
Function expression:
The code copy is as follows: var myFunction=function(params){
//Execution statement
}
Copy the code as follows: var myFunction = function(){
//Execution statement
}
Copy the code as follows: myFunction();//Calling the function
Anonymous function, which is often passed as a parameter between other functions:
The code copy is as follows: window.addEventListener('load',function(){
//Execution statement
},false);
5. Object
An important function of Javascript is the object-oriented function. Through object-based programming, program development can be carried out in a more intuitive, modular and reusable way.
A set of attributes containing data and methods that operate on data contained in attributes are called objects. For example, if you want to set the background color of the web page, the object you are targeting is document, and the attribute name used is bgcolor, such as document.bgcolor="blue", which means that the background color is blue.
6. Events
The actions generated when a user interacts with a web page are called events. Events can be triggered by the user, or the page may change, or even events that you cannot see (such as Ajax's interaction progress changes). Most events are caused by user actions, such as: if the user presses the mouse button, a click event will be generated, and if the mouse pointer moves on the link, a mouseover event will be generated, etc. In Javascript, events are often used in conjunction with event handlers.
For the processing of events, W3C's method is to use the addEventListener() function, which has three parameters: event, the raised function, and whether to use event capture. For security, it is recommended to always set the third parameter to false;
The traditional method is to define the on... event of the element, which is to add an "on" before the event parameter in the W3C method. The IE event model uses attachEvent and dettachEvent to bind and delete events. Events in JavaScript are also divided into two stages: capture and bubble events, but traditional binding only supports bubble events.
7. Variables
For example, var myVariable = "some value";
The variable has its type. In the example above, the type of myVariable is string (string)
Common types supported by javascript include:
object: object
array: array
number: number
boolean: Boolean, only true and false values, are the ones with the least memory occupancy among all types.
null: a null value, the only value is null
undefined: variables without definition and assignment
In fact, JavaScript variables are weak variable types. What you assign to it is a string, and it is a String.
If it is a number, he is plastic surgery. True and false are boolean types (note that you cannot add quotes, otherwise they will be treated as strings).
The above is the basic syntax of js. I hope you can give you a reference and I hope you can support Wulin.com more.