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>感谢大家观看,我们下次见
以后焦虑了或者迷茫了记得回来看看
我非常喜欢 出行博客。鼓舞人心查看路线。
你们的博客 百分百 帮助选择路线。坚持!
信息丰富的 出行资源! 越来越棒!
My brother suggested I might like this blog. He was entirely right. This post actually made my day. You cann't imagine just how much time I had spent for this information! Thanks!
我热爱, 写得很实在。你的博客 就是 最好的例子。很出色。
I've learn several good stuff here. Certainly price bookmarking for revisiting. I surprise how so much effort you put to make such a great informative website.
It's not my first time to pay a visit this web page, i am visiting this website dailly and get good facts from here every day.
Hello, i think that i saw you visited my site so i got here to go back the want?.I'm trying to find things to improve my web site!I suppose its adequate to use a few of your concepts!!
Touche. Outstanding arguments. Keep up the great effort.