当前位置:网站首页>运算符的基础知识
运算符的基础知识
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
边栏推荐
- 深度学习和神经网络的介绍
- 基于STM32F103ZET6库函数外部中断实验
- Substrate及波卡一周技术更新速递 20220425 - 20220501
- 《第五项修炼》(The Fifth Discipline):学习型组织的艺术与实践
- What is ICMP? What is the relationship between Ping and ICMP?
- Solution of adding st-link to Huada MCU Keil
- maxwell 报错(连接为mysql 8.x)解决方法
- Differences between mongodb and MySQL
- NVIDIA Clara-AGX-Developer-Kit installation
- 实施MES管理系统前,要对哪些问题进行评估
猜你喜欢
![[elt.zip] openharmony paper Club - memory compression for data intensive applications](/img/b3/ab915f0338174cba1a003edc262a5d.png)
[elt.zip] openharmony paper Club - memory compression for data intensive applications

爬取国家法律法规数据库

Core dynamic Lianke rushes to the scientific innovation board: with an annual revenue of 170million yuan, Beifang Electronics Institute and Zhongcheng venture capital are shareholders

openssl客户端编程:一个不起眼的函数导致的SSL会话失败问题

新中大冲刺科创板:年营收2.84亿 拟募资5.57亿

Keras deep learning practice (12) -- facial feature point detection

im即时通讯开发之双进程守护保活实践

binder hwbinder vndbinder

International School of Digital Economics, South China Institute of technology 𞓜 unified Bert for few shot natural language understanding

Camera calibration with OpenCV
随机推荐
使用logrotate对宝塔的网站日志进行自动切割
Tupu digital twin intelligent energy integrated management and control platform
openssl客户端编程:一个不起眼的函数导致的SSL会话失败问题
Photoshop layer related concepts layercomp layers move rotate duplicate layer compound layer
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
【建议收藏】ABAP随笔-EXCEL-4-批量导入-推荐
谈谈线程安全
Bit.Store:熊市漫漫,稳定Staking产品或成主旋律
Row to column and column to row in MySQL
让单测变得如此简单 -- spock 框架初体验
云笔记到底哪家强 -- 教你搭建自己的网盘服务器
什么是 ICMP ?ping和ICMP之间有啥关系?
Cloud native database: the outlet of the database, you can also take off
数仓的字符截取三胞胎:substrb、substr、substring
Open source summer 2022 | opengauss project selected and announced
2022年第一季度消费金融APP用户洞察——总数达4479万人
NVIDIA Clara-AGX-Developer-Kit installation
What is ICMP? What is the relationship between Ping and ICMP?
校园书籍资源共享平台
Market status and development prospect forecast of global tetramethylammonium hydroxide developer industry in 2022