一元加操作符

2017-06-14 16:20:00
admin
原创
457
<!DOCTYPE html>
<html>
	<head>
		<title>
			Unary Plus/Minus Example 1
		</title>
		<script type="text/javascript">
			var s1 = "01";
			var s2 = "1.1";
			var s3 = "z";
			var b = false;
			var f = 1.1;
			var o = {
				valueOf: function() {
					return - 1;
				}
			};

			s1 = +s1; //value becomes numeric 1
			s2 = +s2; //value becomes numeric 1.1
			s3 = +s3; //value becomes NaN
			b = +b; //value becomes numeric 0
			f = +f; //no change, still 1.1
			o = +o; //value becomes numeric
			alert(s1);
			alert(s2);
			alert(s3);
			alert(b);
			alert(f);
			alert(o);
		</script>
	</head>
	<body>
	</body>
</html>
  • QQ讨论群
  • 关注微信
    • 欢迎咨询
    • 欢迎加入QQ群 16506021
  • 公众号:源宝网络