티스토리 뷰

728x90
반응형

== 연산자의 경우: 형변환을 자동으로 한 후 값들을 비교한다.

=== 연산자의 경우: 형변환을 하지 않고 값 그 자체를 비교한다.


<!doctype html>

<html>

<head>

</head>

<body>

<h2>Operator == vs ===</h2> 

<p id="equal" style="cursor: pointer;">"1" == 1 클릭</p>

<p>If the two operands are not of the same type, JavaScript converts the operands then applies strict comparison. If either operand is a number or a boolean, the operands are converted to numbers if possible; else if either operand is a string, the other operand is converted to a string if possible. If both operands are objects, then JavaScript compares internal references which are equal when operands refer to the same object in memory.</p>

<br>

   <p id="scriptEqual" style="cursor: pointer;">"1" === 1 클릭</p>

<p>Returns true if the operands are strictly equal (see above) with no type conversion.</p>

<script type="text/javascript">

(function() {

document.getElementById("equal").onclick = function(){

if("1" == 1){

alert("true");

}

else{

alert("false");

}

};

document.getElementById("scriptEqual").onclick = function(){

if("1" === 1){

alert("true");

}

else{

alert("false");

}

};

})();

</script>

</body>

</html>



728x90
반응형