JS 操作符

Arithmetic Operators
算术运算符

OperatorDescriptionExampleResult
+Addition
x=2
y=2
x+y
4
-Subtraction
x=5
y=2
x-y
3
*Multiplication
x=5
y=4
x*y
20
/Division
15/5
5/2
3
2.5
%Modulus (division remainder)
余数
5%2
10%8
10%2
1
2
0
++Increment
递增
x=5
x++
x=6
--Decrement
递减
x=5
x--
x=4

Assignment Operators
赋值运算符

OperatorExampleIs The Same As
=x=yx=y
+=x+=y x=x+y
-=x-=y x=x-y
*=x*=y x=x*y
/=x/=y x=x/y
%=x%=y x=x%y

Comparison Operators
比较(关系)运算符

OperatorDescriptionExample
==is equal to
等于
5==8 returns false
===is equal to (checks for both value and type)
等于(检查值和类型)*全吻合才算相等
x=5
y="5"

x==y returns true
x===y returns false

!=is not equal
不等于
5!=8 returns true
>is greater than
大于
5>8 returns false
<is less than
小于
5<8 returns true
>=is greater than or equal to
大于等于
5>=8 returns false
<=is less than or equal to
小于等于
5<=8 returns true

Logical Operators
逻辑运算符

OperatorDescriptionExample
&&and
x=6
y=3

(x < 10 && y > 1) returns true

||or
x=6
y=3

(x==5 || y==5) returns false

!not
x=6
y=3

!(x==y) returns true

String Operator
串符(连接作用)

A string is most often text, for example "Hello World!". To stick two or more string variables together, use the + operator.
在文字当中使用的比较多,举例来说“Hello World!”要将两个或多个字符串变量衔接在一起的话就得使用 + 符号

txt1="What a very"
txt2="nice day!"

txt3=txt1+txt2 

The variable txt3 now contains "What a verynice day!".
txt3变量现在包含“What a verynice day!”(把1和2衔接起来了)

To add a space between two string variables, insert a space into the expression, OR in one of the strings.
要给两个字符串变量中间添加空格就得在表达式里插入空格,或在其中的一个加上(空格)

txt1="What a very"
txt2="nice day!"
txt3=txt1+" "+txt2
or
txt1="What a very "
txt2="nice day!"
txt3=txt1+txt2

The variable txt3 now contains "What a very nice day!".
现在变量txt3为“What a very nice day!”

Conditional Operator
条件运算符

JavaScript also contains a conditional operator that assigns a value to a variable based on some condition.
JS有根据条件不同给变量不同值的条件运算符

Syntax
语法

variablename=(condition)?value1:value2 

Example
例子

greeting=(visitor=="PRES")?"Dear President ":"Dear "

If the variable visitor is equal to PRES, then put the string "Dear President " in the variable named greeting. If the variable visitor is not equal to PRES, then put the string "Dear " into the variable named greeting.
如果变量visitor的值等于PRES那么greeting的值就为"Dear President "。如果不为PRES那么greeting的值就为"Dear"

 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值