An expression is a phrase in JavaScript that the JavaScript interpreter calculates as a result. The simplest type of expression in a program is the variable. The variable name is also a simple expression whose value is the value assigned to the variable.
Complex expressions are made up of simple expressions. For example, an array access expression consists of an expression that represents an array, a square bracket, and an integer expression. The result of their new expression operation is the element value at the specific location of the array. The same letter
A number call expression consists of an expression representing a function object and 0 more than one parameter expression. The most common method of composing a simple expression into a complex expression is the operator.
This chapter (this article) will explain all JavaScript operators. It also explains expressions that do not involve operators (such as accessing array elements and function calls), and whose syntax and programming style are similar to the C language.
1. Element expressions
The simplest expression is the original expression, which is the smallest unit of the expression-they do not contain other expressions. The original expression in JavaScript contains constants or direct quantities. Keywords and variables.
Direct volume is a constant value that appears directly in the program. They look like:
// Digital Direct Volume // String Direct amount // Direct amount of regular expression
Some reserved words in JavaScript make up the original expression
true // Boolean value: True false // Fake NULL // returns a value: Empty This // returns the current object
Through the third chapter of learning, unlike other keywords, this is not a constant, he returned in different places of the program value is not the same. This keyword is often present in object-oriented programming. This returns the object of the square method.
Finally, the third primitive expression is the variable
// returns the value of the variable i // returns the value of sum // is a global variable, and null differs, it is not a keyword
2. Initialization expressions for objects and arrays.
Object and array initialization are actually newly created objects and arrays, which are sometimes called "Object direct quantities" and "arrays direct quantities". Unlike Boolean direct quantities, however, they are not primitive expressions because they contain members or elements that are sub-expressions.
the initialization expression syntax for arrays is very simple and we start with the following
The initialization expression of an array is made up of a comma-delimited list of parentheses and a new array created by the initialization result . The elements of the array are the values of the comma-delimited expression.
// an empty array, or empty inside [] to indicate that the array has no elements // There are two elements of the array, the first 3, and the second one is 7
An element initialization expression in an array initialization expression can be an array initialization expression. Which means that expressions can be nested.
var mat = [[1,2,3],[4,5,6],[7,8,9]];
The elements between the lists in the array's direct amount can be omitted, and the empty spaces are populated with undefined. For example:
var a=[1,,,, 5]
4 of these elements are undefined. A comma is left at the end of the array's direct amount, and a new element with a value of undefined is not created.
object initialization Expressions and array initialization expressions are very similar, except that square brackets are replaced by curly braces. And each word expression contains a property name and a non-colon as the prefix.
var // an object that has two attribute members var // Empty Object q.x=2.1;q.y=-3; // Q's attribute member is the same as P
Object Direct amount can also be nested, such as
var anh = {left:{x:2,y:3}, right:{x:4,y:5}}
When JavaScript computes the value of an object's initialization expression, the object expression is evaluated once, and they do not have to contain constant values: they can be arbitrary javascript expressions. Similarly, the name of an attribute in an object's direct volume can be a string rather than an identifier. (Useful when you can only use reserved words or some illegal identifiers as property names on that line)
var side = 1; var square = {"Left": {x:p.x,y:p.y}, ' right ': {x:p.x+side,y:p.y+side}}
6th 7 also discusses object and array initialization expressions again.
3. Function expressions
(not to be continued)
Chapter Fourth: JavaScript Expressions and operators