01.算数运算符的使用
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
// + - * /
var num1 = 5
var num2 = 8
var result1 = num1 * num2
console.log(result1)
// %:取余操作
var null = 200
var result2 = num % 8
console.log(result2)
// **:2**3 2的三次方
console.log(2 ** 4)
console.log(Math.pow(2,4))
</script>
</body>
</html>
02.赋值运算符的使用
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
// =赋值运算符
var num = 123
// 链式赋值
var num1 = num2 = num3 = 321
console.log(num1,num2,num3);
</script>
</body>
</html>
03.原地修改的使用
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
var num = 100
// num = num + 10
num += 10
// num = num * 10
num *= 10
num **= 2
console.log(num)
</script>
</body>
</html>
04.自增和自减的使用
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
var currentIndex = 5
// 方法一:
currentIndex = currentIndex + 1
// 方法二:
currentIndex += 1
// 方法三:自增
currentIndex++
console.log(currentIndex)
// 自减
// currentIndex -= 1
currentIndex--
console.log(currentIndex)
</script>
</body>
</html>
05.自增和自减的位置
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
var currentIndex = 5;
// 自己自增或者自减是没有区别
// ++currentIndex
// console.log(currentIndex)
// --currentIndex
// console.log(currentIndex)
// 自增和自减表达式本身又在其他表达式中,那就有区别
var result1 = 100 + currentIndex++
console.log(currentIndex)
console.log("result1:"+result1)
var result2 = 100 + ++currentIndex
console.log(currentIndex)
console.log("result2:"+result2);
</script>
</body>
</html>
06.运算符的优先级
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
var num = 5;
var result = 2 + 3 * ++num
console.log(result)
</script>
</body>
</html>
07.比较运算符的使用
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
// var book = {
// price:{
// newPrice:222,
// oldPrice:188
// }
// }
var num1 = 200
var num2 = 30
// 1.比较运算符
var isResult = num1 > num2
console.log(isResult)
// 2. ==判断
console.log(num1 == num2)
console.log(num1 != num2)
// 需求:获取比较大的哪个值
// var result = 0
// if(num1 > num2){
// result = num1
// }else{
// result = num2
// }
</script>
</body>
</html>
08.==和===的区别
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
var foo1 = 0
var foo2 = ""
// ==运算符,在类型不相同的情况下,会将运算符先转换成Number的值,再进行比较(隐式转换)
// null比较特殊:null在进行比较的时候,应该是会被当成是一个对象和原生类型进行比较的
console.log(Number(foo1))
console.log(Number(foo2))
console.log(foo1 == foo2)
// ===运算符,在类型不同的情况直接返回
console.log(foo1 === foo2);
</script>
</body>
</html>
09.==比较的补充(了解)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
var info = {
name:"why",
age:18,
[Symbol.toPrimitive](){
return 123
}
}
console.log(123 == info)
</script>
</body>
</html>
感谢大家观看,我们下次见
十天看一部剧,还可以吧
@梦不见的梦 行,谢谢提醒,我优化一下
网站的速度有待提升,每次打开都要转半天还进不来呢
@React实战爱彼迎项目(二) - 程序员鸡皮 哪里有问题了,报错了吗?
@Teacher Du 那是怕你们毕不了业,我大学那会儿给小礼品
我们大学那会,献血还给学分~
@ab 我想去学网安,比如网警,但分也贼高😕
@夜 加油,你一样也可以成为程序员的,需要学习资料可以V我
佬发布的好多技术文章似乎我只能评论这篇,真正的程序员!!哇塞 我也想去献血,过两年就成年了可以去献血了