An expression statement is actually an expression, which is composed of operators connecting variables or direct quantities. Generally speaking, the expression statement is either a function call, an assignment, or an increment or decrement, otherwise the result of the expression calculation has no meaning.
The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.
An expression statement is actually an expression, which is composed of operators connecting variables or direct quantities.
Generally speaking, expression statements are either function calls, assignments, or self-increment or self-decrement, otherwise the result of the expression calculation has no meaning.
There is no such restriction in JavaScript syntax. Any legal expression can be used as an expression statement.
a + b;
This line of code calculates the value of the addition of a and b, but it will not be displayed or produce any execution effect (unless a and b are getters), but it does not prevent it from complying with the grammar. be executed.
PrimaryExpression Primary expression
The atomic item of expression: Primary Expression. It is the smallest unit of expression, and the grammatical structure it involves also has the highest priority.
Primary Expression contains various "direct quantities". Direct quantities are values of a specific type that are written directly using a certain syntax. Direct quantities are the syntax for writing them out in code.
JavaScript can define objects in the form of direct quantities. JavaScript provides grammatical support for special object types such as functions, classes, arrays, and regular expressions.
({}); (function(){}); (class{ }); []; /abc/g;
At the grammatical level, expression statements starting with function, { and class have grammatical conflicts with declaration statements. If you want to use such expressions, you must add parentheses to avoid grammatical conflicts.
Primary Expression can also be this or a variable. In syntax, the variable is called an "identifier reference".
this; myVarFun;
Any expression plus parentheses is considered a Primary Expression. This mechanism makes parentheses a means of changing the priority of operations.
(a + b);
MemberExpression Member Expression
Member Expression is usually used to access object members. It has several forms:
a.b; a["b"]; new.target; super.b;
new.target is a newly added syntax, used to determine whether the function is called by new, super is the syntax used to access the properties of the parent class in the constructor.
Member Expression was originally designed for attribute access, but due to syntactic structure requirements, the following two types are regarded as Member Expressions in the JavaScript standard:
Template with function, this one with function The named template means that each part of the template is calculated and passed to a function.
f`a${b}c`;
The new operation with a parameter list and the new operation without a parameter list have a lower priority and do not belong to Member Expression.
new Cls();
They belong to the same priority as attribute operations, but have no semantic relationship.
NewExpression NEW expression
Member Expression plus new is New Expression (New Expression can also be formed without adding new, which is an independent high-priority expression by default in JavaScript can form low-priority expressions).
New Expression specifically refers to an expression without a parameter list. The following code:
new new Cls(1);
Intuitively, it may have two meanings:
new (new Cls(1));
new (new Cls)(1);
In fact, it is equivalent to the first one. Use the code to verify:
class Cls{ constructor(n){ console.log("cls", n); return class { constructor(n) { console.log("returned", n); } } } } new (new Cls(1));
Running results: This shows that 1 is passed in as a parameter when calling Cls.
CallExpression Function call expression
Member Expression can also constitute Call Expression. Its basic form is Member Expression followed by a parameter list in parentheses, or the super keyword can be used instead of Member Expression.
a.b(c); super();
This seems simple, but there are some variations to it. For example:
a.b(c)(d)(e); a.b(c)[3]; a.b(c).d; a.b(c)`xyz`;
The forms of these variations are almost one-to-one correspondence with Member Expression. In fact, it can be understood that if a certain substructure in Member Expression has a function call, then the entire expression becomes a Call Expression. The Call Expression loses the feature of higher priority than the New Expression, which is a major difference.
LeftHandSideExpression lvalue expression
New Expression and Call Expression are collectively called LeftHandSideExpression, lvalue expression.
An lvalue expression is an expression that can be placed on the left side of the equal sign. The JavaScript syntax is:
a() = b;
Such usage is actually grammatical, but the values returned by native JavaScript functions cannot be assigned. Therefore, most of the time, the assignments we see will be other forms of Call Expression, such as:
a().c = b;
According to the design of the JavaScript runtime, it is not ruled out that some hosts will provide functions that return reference types. At this time, The assignment is valid.
左值表达式最经典的用法是用于构成赋值表达式,但是其实如果翻一翻 JavaScript 标准,就会发现它出现在各种场合,凡是需要“可以被修改的变量”的位置,都能见到它的身影。
AssignmentExpression 赋值表达式
AssignmentExpression 赋值表达式也有多种形态,最基本的当然是使用等号赋值:
a = b
等号是可以嵌套的:
a = b = c = d
连续赋值,是右结合的,它等价于下面这种:
a = (b = (c = d))
先把 d 的结果赋值给 c,再把整个表达式的结果赋值给 b,再赋值给 a。
赋值表达式的使用,还可以结合一些运算符,例如:
a += b;
相当于:
a = a + b;
能有这样用的运算符有下面这几种:
*=、/=、%=、+=、-=、<<=、>>=、>>>=、&=、^=、|=、**=
赋值表达式的等号左边和右边能用的表达式类型不一样。
Expression 表达式
赋值表达式可以构成 Expression 表达式的一部分。在 JavaScript 中,表达式就是用逗号运算符连接的赋值表达式。
在 JavaScript 中,比赋值运算优先级更低的就是逗号运算符了。可以把逗号可以理解为一种小型的分号。
a = b, b = 1, null;
逗号分隔的表达式会顺次执行,就像不同的表达式语句一样。“整个表达式的结果”就是“最后一个逗号后的表达式结果”。比如之前的例子,整个“a = b, b = 1, null;”表达式的结果就是“,”后面的null。
在很多场合,都不允许使用带逗号的表达式,比如我export 后只能跟赋值表达式,意思就是表达式中不能含有逗号。
【推荐学习:javascript高级教程】
The above is the detailed content of What is an expression in javascript. For more information, please follow other related articles on the PHP Chinese website!

Different JavaScript engines have different effects when parsing and executing JavaScript code, because the implementation principles and optimization strategies of each engine differ. 1. Lexical analysis: convert source code into lexical unit. 2. Grammar analysis: Generate an abstract syntax tree. 3. Optimization and compilation: Generate machine code through the JIT compiler. 4. Execute: Run the machine code. V8 engine optimizes through instant compilation and hidden class, SpiderMonkey uses a type inference system, resulting in different performance performance on the same code.

JavaScript's applications in the real world include server-side programming, mobile application development and Internet of Things control: 1. Server-side programming is realized through Node.js, suitable for high concurrent request processing. 2. Mobile application development is carried out through ReactNative and supports cross-platform deployment. 3. Used for IoT device control through Johnny-Five library, suitable for hardware interaction.

I built a functional multi-tenant SaaS application (an EdTech app) with your everyday tech tool and you can do the same. First, what’s a multi-tenant SaaS application? Multi-tenant SaaS applications let you serve multiple customers from a sing

This article demonstrates frontend integration with a backend secured by Permit, building a functional EdTech SaaS application using Next.js. The frontend fetches user permissions to control UI visibility and ensures API requests adhere to role-base

JavaScript is the core language of modern web development and is widely used for its diversity and flexibility. 1) Front-end development: build dynamic web pages and single-page applications through DOM operations and modern frameworks (such as React, Vue.js, Angular). 2) Server-side development: Node.js uses a non-blocking I/O model to handle high concurrency and real-time applications. 3) Mobile and desktop application development: cross-platform development is realized through ReactNative and Electron to improve development efficiency.

The latest trends in JavaScript include the rise of TypeScript, the popularity of modern frameworks and libraries, and the application of WebAssembly. Future prospects cover more powerful type systems, the development of server-side JavaScript, the expansion of artificial intelligence and machine learning, and the potential of IoT and edge computing.

JavaScript is the cornerstone of modern web development, and its main functions include event-driven programming, dynamic content generation and asynchronous programming. 1) Event-driven programming allows web pages to change dynamically according to user operations. 2) Dynamic content generation allows page content to be adjusted according to conditions. 3) Asynchronous programming ensures that the user interface is not blocked. JavaScript is widely used in web interaction, single-page application and server-side development, greatly improving the flexibility of user experience and cross-platform development.

Python is more suitable for data science and machine learning, while JavaScript is more suitable for front-end and full-stack development. 1. Python is known for its concise syntax and rich library ecosystem, and is suitable for data analysis and web development. 2. JavaScript is the core of front-end development. Node.js supports server-side programming and is suitable for full-stack development.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

WebStorm Mac version
Useful JavaScript development tools