JavaScript中几种=的用法比较

设a=8

1."=":赋值运算符, 例子:b=a 结果为8
2."==":比较运算符等于,例子:a==12 结果为false
3."===":比较运算符全等(值和类型),例子:a===8 结果为true,a==="8"结果为false

把下面代码复制到html里面试试吧

 

<!doctype html>

<html>

<head>

<title>==</title>

<meta http-equiv="content-type" content="text/html;charset=UTF-8">

</head>

<body>

<script>

var a=8;

b = a;

document.write("=演示b=a b的值为:");

document.write(b);

document.write("<br/><br/>");

document.write("==演示a==7 比较结果为");

document.write(a==7);

document.write("<br/><br/>");

document.write("===演示a===8 比较结果为:");

document.write(a===8);

document.write("<br/>===演示a==='8' 比较结果为:");

document.write(a==='8');

</script>

</body>

</html>