首页 > 代码库 > cocos2d JS 基础语法运算符

cocos2d JS 基础语法运算符

<style>p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px "PingFang SC" }</style>

 

简单且逼格高的运算符

 

 var a = 12;
 console.log(-a);        //输出 -12   - -> 取反
 
 var b = a++;
 console.log(b);        //输出 12   - -> 先赋值b,a再++
 
 b = ++a;
 console.log(b);        //输出 14   - -> ++a赋值b,a先++后赋值

 

 var a = 1;
 var b = 2;
 a += b;        //相当于 a = a + b
 console.log(a);        //输出 3
 
a += b + 3; //相当于 a = a + b + 3 console.log(a); //输出 8
a -= b; //相当于 a = a - b console.log(a); //输出 6
a *= b; //相当于 a = a * b console.log(a); //输出 12
a /= b; //相当于 a = a / b console.log(a); //输出 6
a %= b; //相当于 a = a % b console.log(a); //输出 0

 

<style>p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px "PingFang SC" }</style>

三目运算符

var  score = 80;

var result = score > 60 ? “及格”:“不及格”;

console.log(result);          //输出 及格

 

cocos2d JS 基础语法运算符