1. 递增递减运算符
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script>
// 前置递增运算符
var age=10
++age //类似于age=age+1, 先加1后返回值
alert(age)
// 后置递增运算符
var num=10
num++
alert(num)
// 前置自增和后置自增如果单独使用,效果是一样的
// 2. 后置自增口诀:先返回原值,后自加1
</script>
</head>
<body>
</body>
</html>
2 逻辑中断
2.1 逻辑与
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script>
// 如果表达式1 结果为真,则返回表达式2 如果表达式1 结果为假,则返回表达式1
alert(0 && 123)
alert(123 && 456)
</script>
</head>
<body>
</body>
</html>
2.2 逻辑或
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script>
// 如果表达式1 结果为真,则返回表达式1 如果表达式1 结果为假,则返回表达式2
alert(0||111)
alert(123||456)
</script>
</head>
<body>
</body>
</html>
3. if条件判断
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script>
if (0) {
alert("hello world")
} else {
alert("error")
}
</script>
</head>
<body>
</body>
</html>
4. switch分支语句
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script>
switch (2) {
case 1:
alert("1")
break
case 2:
alert("2")
break
case 3:
alert("3")
break
default:
alert("没有匹配结果")
}
</script>
</head>
<body>
</body>
</html>
5. for循环
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script>
for (var i=1; i<=100; i++){
alert("hello world")
}
</script>
</head>
<body>
</body>
</html>
6. while循环
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script>
var num = 1
while (num<=100) {
alert('Hello World')
}
</script>
</head>
<body>
</body>
</html>