示例代码:
var a = 10, b = 20;// 加法运算console.log(30 === a + b);// 减法运算console.log(-10 === a - b);// 乘法运算console.log(200 === a * b);// 除法运算console.log(0.5 === a / b);// 取余运算console.log(10 === a % b);
加法运算(+)也可以用作字符串的拼接。
var a = '.w' , b = 'xs';// 字符串拼接console.log('.wxs' === a + b);一元运算符
示例代码:
var a = 10, b = 20;// 自增运算console.log(10 === a++);console.log(12 === ++a);// 自减运算console.log(12 === a--);console.log(10 === --a);// 正值运算console.log(10 === +a);// 负值运算console.log(0-10 === -a);// 否运算console.log(-11 === ~a);// 取反运算console.log(false === !a);// delete 运算console.log(true === delete a.fake);// void 运算console.log(undefined === void a);// typeof 运算console.log( number === typeof a);
示例代码:
var a = 10, b = 20;// 左移运算console.log(80 === (a 2));// 带符号右移运算console.log(2 === (a 2));// 与运算console.log(2 === (a amp; 3));// 异或运算console.log(9 === (a ^ 3));// 或运算console.log(11 === (a | 3));比较运算符
示例代码:
var a = 10, b = 20;// 小于console.log(true === (a b));// 小于等于console.log(true === (a = b));等值运算符
示例代码:
var a = 10, b = 20;// 等号console.log(false === (a == b));// 非等号console.log(true === (a != b));// 全等号console.log(false === (a === b));// 非全等号console.log(true === (a !== b));赋值运算符
示例代码:
var a = 10; a = 10; a *= 10;console.log(100 === a); a = 10; a /= 5;console.log(2 === a); a = 10; a %= 7;console.log(3 === a); a = 10; a += 5;console.log(15 === a); a = 10; a -= 11;console.log(-1 === a); a = 10; a = 2;console.log(2 === a); a = 10; a = 2;console.log(2 === a); a = 10; a amp;= 3;console.log(2 === a); a = 10; a ^= 3;console.log(9 === a); a = 10; a |= 3;console.log(11 === a);二元逻辑运算符
示例代码:
var a = 10, b = 20;// 逻辑与console.log(20 === (a amp; amp; b));// 逻辑或console.log(10 === (a || b));其他运算符
示例代码:
var a = 10, b = 20;//条件运算符console.log(20 === (a = 10 ? a + 10 : b + 10));//逗号运算符console.log(20 === (a, b));运算符优先级
相信看了本文案例你已经掌握了方法,更多精彩请关注php中文网其它相关文章!
推荐阅读:
微信小程序开发中怎样实现Android环境下的横向滚动
以上就是微信小程序内常用的运算符有哪些的详细内容,更多请关注php中文网其它相关文章!
微信app下载
微信是一款手机通信软件,支持通过手机网络发送语音短信、视频、图片和文字。微信可以单聊及群聊,还能根据地理位置找到附近的人,带给大家全新的移动沟通体验,有需要的小伙伴快来保存下载体验吧!