Logic and
Logical Operators
- &&:与
- ||: or
- ! :non
Logic and
&& and (as long as a condition is not satisfied, return false)
Description:
In the case where one operand is not a Boolean value, the return value is not necessarily a logical AND operation, then it follows the following rules:
- If the first operand is implicit type conversion to true, then returns the second operand 1
- If the first operand is implicit type conversion to false, then returns the first operand 1
- If either operand is null, or null 2
- If there is an operand is a NaN, then returns NaN3 2
- If either operand is undefined, the return undefined 2
Programming Exercises
Write code hands-on look at these two sets of data (x && y), (m && n) returns results What:
First set: x = 0, y = undefined ;
the second group: m = 1, n = " imooc"
task
- Define two sets of data
- "And" the number of these two groups is determined using logical operators
- The output of the page
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>逻辑操作符</title>
</head>
<body>
<script>
var x=0,y=undefined;
var m=1,n="imooc";
document.write(x&&y);
document.write(m&&n);
</script>
</body>
</html>