Basic JavaScript syntax
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 operation (?:), displacement operator (|,&,<<,>>,~,^) and string operator (+).
Many people may not know what "===".
Here, I will explain to you that in javascript "===" is the congruent. Only "===" the memory addresses on both sides are also equal and will return true.
And "=="Just the values are equal and return true
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 statements, switch selection statements, while loop statements, for loop statements, for each loop statements, do while loop statements, break loop abort statements, continue loop interrupt statements, with statements, try...catch statements, if statements (if..else, if...else if...), let statements.
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 using 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 the function name cannot be written incorrectly 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 refers to 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.
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.
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 of the things are caused by the user's actions, such as: if the user presses the mouse button, a click event will be generated, and if the mouse pointer link moves on, a mouseover event will be generated, etc.
In Javascript, events are often used in conjunction with event handlers.
7. Variables
For example, var myVariable = "some value";
Variable has its type. In the above example, the type of myVariable is string (string)
Common types supported by javascript are also:
object: object
array: array
number: number;
boolean: Boolean, with only two values, true and false, which 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, which is a String. If it is a number, it is a plastic surgery.
True and false are boolean types (note that you cannot add quotes, otherwise they will be treated as strings).
The above content introduces the basic JavaScript syntax for the basic JavaScript entry, and I hope it will be helpful to everyone.