导航
当前位置:首页>>小程序

微信小程序WXS语法的运算符有哪些

2023-12-02 围观 : 0次

今天我们来一起来看看微信小程序WXS语法的运算符有哪些:

基本运算符

示例代码:

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 << 3));// 无符号右移运算console.log(2 === (a >> 2));// 带符号右移运算console.log(2 === (a >>> 2));// 与运算console.log(2 === (a & 3));// 异或运算console.log(9 === (a ^ 3));// 或运算console.log(11 === (a | 3));

比较运算符

示例代码:

var a = 10, b = 20;

// 小于console.log(true === (a < b));// 大于console.log(false === (a > b));// 小于等于console.log(true === (a <= b));// 大于等于console.log(false === (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 <<= 10;console.log(10240 === a);a = 10; a >>= 2;console.log(2 === a);a = 10; a >>>= 2;console.log(2 === a);a = 10; a &= 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 && 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));

运算符优先级

相关文章
  • 西安小程序开发工具模拟软件

    小程序是一种轻量级的应用程序,可以在微信、支付宝等应用内运行。随着移动互联网的普及,小程序成为了企业宣传、产品推广和服务提供的新渠道,具有很大的市场潜力。西安小程序开发工具模拟软件是一种专门为小程序开发者提供的开发工具,可以通过模拟程序的运行状况来帮助开发者进行调试和测试,提高开发效率。西安小程序开...

    2023-12-01
  • 微信小程序开发工具字体真小

    微信小程序开发工具是一款专门用于开发和调试微信小程序的工具。然而,很多人在使用微信小程序开发工具时都会发现一个问题:字体过小!这不仅令人困扰,而且还让开发者难以看清文本内容,影响了开发效率。那么,为什么微信小程序开发工具的字体这么小呢?下面我们来一起探讨一下。首先,要了解为什么微信小程序开发工具的字...

    2023-11-29
  • 微信小程序开发工具怎么下载使用

    微信小程序开发工具是微信官方提供的集成开发环境,方便开发者在本地进行小程序的开发、调试和发布。本文将详细介绍微信小程序开发工具的下载、使用及原理。**一、微信小程序开发工具的下载**微信小程序开发工具可以在微信官方开发者平台上下载,下载地址为:[https://developers.weixin.q...

    2023-11-29
  • 广西平台小程序开发工具哪家好

    在小程序开发工具的选择上,广西地区也并不例外。广西平台小程序开发工具的选择除了要考虑基本的开发功能外,还需要考虑地域所需的文化背景和语言特点等因素。下面就是小编为大家带来的广西平台小程序开发工具的介绍。一、梦想易制作梦想易制作是一个极富创新性的小程序开发平台。这个平台专注于各个行业的应用开发,业务领...

    2023-10-30
  • 微信小程序开发js代码教程

    之前和大家介绍了什么是微信小程序开发js代码,今天就和大家介绍一下微信小程序开发js代码教程。步骤一:打开微信小程序开发js编辑页面打开index.js编辑页面,我们先把这页面的所有内容都清空,然后输入Page,开发者工具会弹出提示,这时按tab键即可生成默认代码。①.Page({}) 包括页面的所...

    2023-11-13