当前位置:网站首页>运算符的基础知识
运算符的基础知识
2022-06-27 17:34:00 【编程奥特曼.】
运算符
算术运算符
在运算的时候,需要前后空格隔开, +:有字符串的参与,就会变成拼接 -:尽力去把俩侧的数据变成数值, * , / %:模,取余,大模小,取余,小模大,取小, **
let num = 1 + 2;
let num1 = "1" + 2
console.log(num);//3
console.log(num1);//12
// 100 设置到style里的width top left "100px"
let num3 = 100 + "px"
console.log(num3);
let a;
let num3 = "123" - a
console.log(num3); //NaN
let num3 = 100 / 0
console.log(num3); //Infinity
let num = 0 / 0
console.log(num);//NaN
let num = 6 % 5
console.log(num); //1
let num3 = 4 % 9
console.log(num3); //4
let num4 = 3 ** 3
console.log(num4);//27
赋值运算符
let obj = {
name:'雀雀',
age:3
}
let a = obj.age
obj.age = 108
console.log(a);//3
let obj = {
name:'雀雀',
age:[1,2]
}
let a = obj.age
obj.age[0] = 2
console.log(a[0]);//2
前置++和后置++的区别
前置和后置在不赋值的时候,结果是一样的,
在有赋值的时候:前置:先运算后赋值,后置:先赋值,在运算
let num = 1
// num = num + 1
num += 5
console.log(num); //2
// 没有赋值行为
let num = 9
++num
console.log(num); //10
// 有赋值行为
let x = 9
let num1 = ++x //前置需要先运算,在赋值
console.log(num1);//10
let y = 9
let num2 = y++ //后置需要先赋值,后运算
console.log(num2);//9
比较运算符
一般会出现在判断条件的时候,通过比较返回一个布尔值,满足条件则为true,不满足条件则为false
=
<
<=
== 判断是不是相等 不看数据类型 相等true 不相等false
!=
上面的这些比较运算符 如果一侧为数值型的话,会把另外一侧尽力转成数值去进行大小的比较
=== 全等于 严格比较 要求类型一致 不会进行类型转换
!== 全不等于 严格比较
let bool = 2 > 1
console.log(bool); //true
let bool = undefined === undefined
console.log(bool); //true
let bool = NaN === NaN
console.log(bool); //false
let bool = [] === []
console.log(bool);//false
let arr = [] //[]1的地址
let arr1 = arr //[]1的地址
console.log(arr === arr1); //true
let bool = {
} === {
}
console.log(bool); //false
let bool = {
} == {
}
console.log(bool); //false 只要是不同的对象 怎么都不相等
逻辑运算符
&&与:遇到true就通过,遇到false就停下并返回值,(过真留假,喜欢假的)
||或: 遇到false就通过,遇到true就停下并返回值(过假留真,喜欢真货)
!非:取反 转成相反的布尔值 !!取俩次反,则变成值所对应转换的布尔值
优先级是先非在与后或
let a = 1 && 0
console.log(a); //0
let a = 1 && 2 && "123"
console.log(a) //123;
let zq = "" && [1] || null || function(){
}
console.log(zq); //fun
边栏推荐
- 什么是 ICMP ?ping和ICMP之间有啥关系?
- Camera calibration with OpenCV
- 如何实现IM即时通讯“消息”列表卡顿优化
- Add in address of idea official website
- 数仓的字符截取三胞胎:substrb、substr、substring
- NVIDIA Clara-AGX-Developer-Kit installation
- 你知道 log4j2 各项配置的全部含义吗?带你了解 log4j2 的全部组件
- Market status and development prospect forecast of global 4-methyl-2-pentanone industry in 2022
- Market status and development prospect forecast of global 3-Chloro-1,2-Propanediol industry in 2022
- Seven phases of CMS implementation
猜你喜欢

Two methods of MySQL database login and logout

Function key input experiment based on stm32f103zet6 Library

Win10 LTSC 2021 wsappx CPU usage high

Jinyuan's high-end IPO was terminated: it was planned to raise 750million Rushan assets and Liyang industrial investment were shareholders

在arcgis中以txt格式导出点的坐标

Bit. Store: long bear market, stable stacking products may become the main theme

“我让这个世界更酷”2022华清远见研发产品发布会圆满成功

利用OpenCV执行相机校准

Error reported by Huada MCU Keil_ Weak's solution

基于STM32F103ZET6库函数跑马灯实验
随机推荐
Technology sharing | introduction to kubernetes pod
通过 G1 GC Log 重新认识 G1 垃圾回收器
Blink SQL内置函数大全
Labelimg usage guide
如何利用 RPA 实现自动化获客?
New Zhongda chongci scientific and Technological Innovation Board: annual revenue of 284million and proposed fund-raising of 557million
如何封装调用一个库
Market status and development prospect forecast of global aircraft hose industry in 2022
Is it safe to buy stocks and open an account on the account opening link of the securities manager? Ask the great God for help
Code and principle of RANSAC
Market status and development prospect forecast of the global shuttleless air jet loom industry in 2022
电脑安全证书错误怎么处理比较好
Market status and development prospect forecast of global epoxy resin active toughener industry in 2022
Win10 LTSC 2021 wsappx CPU usage high
实战回忆录:从Webshell开始突破边界
工作流自动化 低代码是关键
TIA博途_基于SCL语言制作模拟量输入输出全局库的具体方法
The IPO of Yuchen Airlines was terminated: Guozheng was proposed to raise 500million yuan as the major shareholder
laravel框架中 定时任务的实现
Hi,你有一份Code Review攻略待查收!