当前位置:网站首页>运算符的基础知识
运算符的基础知识
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
边栏推荐
- 9.OpenFeign服务接口调用
- Market status and development prospect forecast of global handheld ventilator industry in 2022
- openssl客户端编程:一个不起眼的函数导致的SSL会话失败问题
- 网上期货开户安全么?
- 广发期货开户安全吗?
- ABAP随笔-EXCEL-3-批量导入(突破标准函数的9999行)
- Market status and development prospect of resorcinol derivatives for skin products in the world in 2022
- Row to column and column to row in MySQL
- xctf攻防世界 MISC薪手进阶区
- Making single test so simple -- initial experience of Spock framework
猜你喜欢

基于STM32F103ZET6库函数蜂鸣器实验

Error reported by Huada MCU Keil_ Weak's solution

Row to column and column to row in MySQL

OpenSSL client programming: SSL session failure caused by an obscure function

Hikvision tools manager Hikvision tools collection (including sadp, video capacity calculation and other tools) a practical tool for millions of security practitioners

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

What is ICMP? What is the relationship between Ping and ICMP?

Blink SQL内置函数大全

External interrupt experiment based on stm32f103zet6 library function

Function key input experiment based on stm32f103zet6 Library
随机推荐
【ELT.ZIP】OpenHarmony啃论文俱乐部—数据密集型应用内存压缩
国际数字经济学院、华南理工 | Unified BERT for Few-shot Natural Language Understanding(用于小样本自然语言理解的统一BERT)
Usage of rxjs mergemap
Differences between mongodb and MySQL
让单测变得如此简单 -- spock 框架初体验
实战回忆录:从Webshell开始突破边界
Google Earth Engine(GEE)——ImageCollection (Error)遍历影像集合产生的错误
Keras深度学习实战(12)——面部特征点检测
利用OpenCV执行相机校准
数仓的字符截取三胞胎:substrb、substr、substring
Blink SQL built in functions
Teach you how to install Oracle 19C on Windows 10 (detailed picture and text with step on pit Guide)
什么是SSR/SSG/ISR?如何在AWS上托管它们?
在线文本按行批量反转工具
openssl客户端编程:一个不起眼的函数导致的SSL会话失败问题
Informatics Olympiad 1333: [example 2-2] blah data set | openjudge noi 3.4 2729:blah data set
一对一关系
工作流自动化 低代码是关键
Bit.Store:熊市漫漫,稳定Staking产品或成主旋律
Erreur Keil de Huada Single Chip Computer La solution de Weak