当前位置:网站首页>运算符的基础知识
运算符的基础知识
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
边栏推荐
- OpenSSL client programming: SSL session failure caused by an obscure function
- Market status and development prospect forecast of phenethyl resorcinol for skin care industry in the world in 2022
- Current market situation and development prospect forecast of the global ductless heating, ventilation and air conditioning system industry in 2022
- GIS遥感R语言学习看这里
- Redis 原理 - String
- 一位平凡毕业生的大学四年
- 教你打印自己的日志 -- 如何自定义 log4j2 各组件
- Workflow automation low code is the key
- Hi,你有一份Code Review攻略待查收!
- DFS and BFS simple principle
猜你喜欢

Camera calibration with OpenCV

Running lantern experiment based on stm32f103zet6 library function

GIS遥感R语言学习看这里

Google Earth Engine(GEE)——ImageCollection (Error)遍历影像集合产生的错误

爬取国家法律法规数据库

Teach you how to install Oracle 19C on Windows 10 (detailed picture and text with step on pit Guide)

Minmei new energy rushes to Shenzhen Stock Exchange: the annual accounts receivable exceeds 600million and the proposed fund-raising is 450million

如何实现IM即时通讯“消息”列表卡顿优化

A simple calculation method of vanishing point

Bit. Store: long bear market, stable stacking products may become the main theme
随机推荐
脉脉热帖:为啥大厂都热衷于造轮子?
基于STM32F103ZET6库函数外部中断实验
信息学奥赛一本通 1333:【例2-2】Blah数集 | OpenJudge NOI 3.4 2729:Blah数集
OpenSSL client programming: SSL session failure caused by an obscure function
一位平凡毕业生的大学四年
一对一关系
Informatics Olympiad 1333: [example 2-2] blah data set | openjudge noi 3.4 2729:blah data set
图扑数字孪生智慧能源一体化管控平台
网络传输是怎么工作的 -- 详解 OSI 模型
Photoshop-图层相关概念-LayerComp-Layers-移动旋转复制图层-复合图层
全面解析零知识证明:消解扩容难题 重新定义「隐私安全」
The IPO of Yuchen Airlines was terminated: Guozheng was proposed to raise 500million yuan as the major shareholder
Redis 原理 - String
Workflow automation low code is the key
Making single test so simple -- initial experience of Spock framework
【建议收藏】ABAP随笔-EXCEL-4-批量导入-推荐
什么是 ICMP ?ping和ICMP之间有啥关系?
买股票在券商经理的开户链接上开户安全吗?求大神赐教
Market status and development prospect forecast of global aircraft hose industry in 2022
DFS and BFS simple principle