递增和递减还可以用于字符串、布尔值、浮点数值和对象

2017-06-14 16:18:00
admin
原创
516
<!DOCTYPE html>
<html>
	<head>
		<title>
			Increment/Decrement Example 4
		</title>
		<script type="text/javascript">
			var s1 = "2";
			var s2 = "z";
			var b = false;
			var f = 1.1;
			var o = {
				valueOf: function() {
					return - 1;
				}
			};
			s1++; //value becomes numeric 3
			s2++; //value becomes NaN
			b++; //value becomes numeric 1
			f--; //value becomes 0.10000000000000009
			o--; //value becomes numeric
			alert(s1);
			alert(s2);
			alert(b);
			alert(f);
			alert(o);
		</script>
	</head>
	<body>
	</body>
</html>
  • QQ讨论群
  • 关注微信
    • 欢迎咨询
    • 欢迎加入QQ群 16506021
  • 公众号:源宝网络