JavaScript logical operator (a)

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:

  1. If the first operand is implicit type conversion to true, then returns the second operand 1
  2. If the first operand is implicit type conversion to false, then returns the first operand 1
  3. If either operand is null, or null 2
  4. If there is an operand is a NaN, then returns NaN3 2
  5. 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

  1. Define two sets of data
  2. "And" the number of these two groups is determined using logical operators
  3. 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>


  1. Rule is the case of the two operands ↩︎ ↩︎

  2. After the operand implicit type conversions surface current is to true ↩︎ ↩︎ ↩︎

Published 15 original articles · won praise 16 · views 213

Guess you like

Origin blog.csdn.net/qq_43133192/article/details/104927942