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!
我热爱, 写得很实在。你的博客 就是 最好的例子。很出色。