在编程中,什么是表达式? [英] In programming, what is an expression?
问题描述
我已经搜索了这个问题,并进行了搜索,但是我似乎无法获得直接的答案.
I've Googled this question, and searched on SO, however I can't seem to get a straight answer.
这个问题是不是基本没有人问过?
Is this question so basic no-one has thought to ask it yet?
有人可以解释一下编程中表达式"的确切含义吗?
Can someone please explain what exactly an "expression" is in programming.
我也主要使用Javascript编程,如果JS中的定义不同,还可以请您强调一下区别吗?
Also I program primarily in Javascript, if the definition varies in JS could you please also highlight the difference?
推荐答案
在Java语言中:
表达式是解析为值的任何有效代码单元.
An expression is any valid unit of code that resolves to a value.
从概念上讲,有两种类型的表达式:为变量分配值的表达式和仅具有值的表达式.
Conceptually, there are two types of expressions: those that assign a value to a variable and those that simply have a value.
表达式x = 7是第一种类型的示例.
该表达式使用=运算符将值7分配给变量x.该表达式本身的值为7.
The expression x = 7 is an example of the first type.
This expression uses the = operator to assign the value seven to the variable x. The expression itself evaluates to seven.
代码3 + 4是第二个表达式类型的示例.
该表达式使用+运算符将三个和四个加在一起,而不将结果七个分配给变量.
The code 3 + 4 is an example of the second expression type.
This expression uses the + operator to add three and four together without assigning the result, seven, to a variable.
JavaScript具有以下表达式类别:
JavaScript has the following expression categories:
- 算术:得出一个数字,例如3.14159. (通常使用算术运算符.)
- 字符串:计算为字符串,例如"Fred"或"234". (通常使用字符串运算符.)
- 逻辑:计算结果为true或false. (通常涉及逻辑运算符.)
- 对象:计算为对象. (有关对对象求值的各种运算符,请参见特殊运算符.)"
- Arithmetic: evaluates to a number, for example 3.14159. (Generally uses arithmetic operators.)
- String: evaluates to a character string, for example, "Fred" or "234". (Generally uses string operators.)
- Logical: evaluates to true or false. (Often involves logical operators.)
- Object: evaluates to an object. (See special operators for various ones that evaluate to objects.)"
来源: https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Guide/Expressions_and_Operators
此处是Microsoft对.NET中表达式的解释
here is Microsoft's explanation of expressions in .NET
这篇关于在编程中,什么是表达式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!