Arithmetic Operators
算术运算符

Operator Description Example Result + 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
赋值运算符

Operator Example Is The Same As = x=y x=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
比较(关系)运算符

Operator Description Example == 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
逻辑运算符

Operator Description Example && 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"

标签:
操作符

免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
狼山资源网 Copyright www.pvsay.com

评论“JS 操作符整理[推荐收藏]”

暂无“JS 操作符整理[推荐收藏]”评论...

《魔兽世界》大逃杀!60人新游玩模式《强袭风暴》3月21日上线

暴雪近日发布了《魔兽世界》10.2.6 更新内容,新游玩模式《强袭风暴》即将于3月21 日在亚服上线,届时玩家将前往阿拉希高地展开一场 60 人大逃杀对战。

艾泽拉斯的冒险者已经征服了艾泽拉斯的大地及遥远的彼岸。他们在对抗世界上最致命的敌人时展现出过人的手腕,并且成功阻止终结宇宙等级的威胁。当他们在为即将于《魔兽世界》资料片《地心之战》中来袭的萨拉塔斯势力做战斗准备时,他们还需要在熟悉的阿拉希高地面对一个全新的敌人──那就是彼此。在《巨龙崛起》10.2.6 更新的《强袭风暴》中,玩家将会进入一个全新的海盗主题大逃杀式限时活动,其中包含极高的风险和史诗级的奖励。

《强袭风暴》不是普通的战场,作为一个独立于主游戏之外的活动,玩家可以用大逃杀的风格来体验《魔兽世界》,不分职业、不分装备(除了你在赛局中捡到的),光是技巧和战略的强弱之分就能决定出谁才是能坚持到最后的赢家。本次活动将会开放单人和双人模式,玩家在加入海盗主题的预赛大厅区域前,可以从强袭风暴角色画面新增好友。游玩游戏将可以累计名望轨迹,《巨龙崛起》和《魔兽世界:巫妖王之怒 经典版》的玩家都可以获得奖励。