Archive

Calender

«   2019/09   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30          

자바스크립트에서의 0. ( Zero in javascript )



 
<button onclick="testing()"> Click me </button>
<p id="demo1">   </p>
<p id="demo2">   </p>

<script>
function testing (){
    var x = ""; 
    document.getElementById( "demo1" ).innerHTML = 0 == x; 
    document.getElementById( "demo2" ).innerHTML = 0 === x; 
}
</script>
 
0 == +0 0 === +0 0 != +0 0 !== +0
0 == -0 0 === -0 0 != -0 0 !== -0
0 == false 0 === false 0 != false 0 !== false
0 == "" 0 === "" 0 != "" 0 !== ""
0 == [ ] 0 === [ ] 0 != [ ] 0 !== [ ]
 
<button onclick="testing()"> Click me </button>
<p id="demo3">   </p>
<p id="demo4">   </p>

<script>
function isZero ( x ){  return x === 0;  } 

function testing (){
    var num = 0; 
    var str = ""; 
    document.getElementById( "demo3" ).innerHTML = isZero( num ); 
    document.getElementById( "demo4" ).innerHTML = isZero( str ); 
}
</script>
 
isZero( +0 )
isZero( -0 )
isZero( false )
isZero( "" )
isZero( [ ] )
 
<button onclick="testing()"> Click me </button>
<p id="demo5">   </p>
<p id="demo6">   </p>

<script>
function testing (){
    var a = 1 / +0; 
    var b = 1 / -0; 
    document.getElementById( "demo5" ).innerHTML = a; 
    document.getElementById( "demo6" ).innerHTML = b; 
}
</script>
 
 
function isNegativeZero ( x ){  return x === 0 && (1/x) === -Infinity;  } 
 
isNegativeZero( -0 )
isNegativeZero( +0 )
isNegativeZero( 0 )


https://tonks.tistory.com/236#_zero_in_javascript

이 내용이 도움이 되셨다면, 아래의 하트 버튼을 눌러주세요 (*^^*)
If this posting is helpful to you, please click the heart button below. (*^^*)

0 Comments