Day5逻辑运算符

image

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>逻辑运算符</title>
</head>

<body>
  <script>
    // 逻辑与,一假则假
    console.log(true && true)
    console.log(false && false)
    console.log(3 < 5 && 3 > 2)//true
    console.log(3 < 5 && 3 < 2)//false
    console.log('-----------------------------------------------')
    // 逻辑或,一真则真
    console.log(true || true)//true
    console.log(true || false)//true
    console.log(false || false)//false
    console.log('-----------------------------------------------')
    // 逻辑非,取反
    console.log(!true)//false
    console.log(!false)//true


  </script>
</body>

</html>

练习:
image

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>用户输入</title>
</head>

<body>
  <script>
    // 1.用户输入
    let num = +prompt('请输入数字:')
    // 2.判断条件后弹出结果
    alert(num % 4 === 0 && num % 100 !== 0)
  </script>
</body>

</html>

运算符优先级:
image

posted @ 2026-01-01 21:53  冰涿  阅读(2)  评论(0)    收藏  举报