[ Javascript ] Number.isInteger()
Polyfill
<script type="text/javascript">
Number.isInteger = Number.isInteger || function isInteger ( number ){
return typeof number === "number" && (number % 1 === 0);
};
</script>
Example 1
<button onclick="testing1()"> Click me </button>
<p id="demo1"> </p>
<script type="text/javascript">
function testing1 (){
var result = Number.isInteger( 123 );
demo1.innerHTML = result;
}
</script>
|
<button onclick="testing2()"> Click me </button>
<p id="demo2"> </p>
<script type="text/javascript">
function testing2 (){
var result = Number.isInteger( "123" );
demo2.innerHTML = result;
}
</script>
|
Example 2
<button onclick="testing1()"> Click me </button>
<p id="demo1"> </p>
<script type="text/javascript">
function testing1 (){
var result = Number.isInteger( 0.45 );
demo1.innerHTML = result;
}
</script>
|
<button onclick="testing2()"> Click me </button>
<p id="demo2"> </p>
<script type="text/javascript">
function testing2 (){
var result = Number.isInteger( "0.45" );
demo2.innerHTML = result;
}
</script>
|
Example 3
<button onclick="testing1()"> Click me </button>
<p id="demo1"> </p>
<script type="text/javascript">
function testing1 (){
var result = Number.isInteger( null );
demo1.innerHTML = result;
}
</script>
|
<button onclick="testing2()"> Click me </button>
<p id="demo2"> </p>
<script type="text/javascript">
function testing2 (){
var result = Number.isInteger( undefined );
demo2.innerHTML = result;
}
</script>
|
Example 4
<button onclick="testing1()"> Click me </button>
<p id="demo1"> </p>
<script type="text/javascript">
function testing1 (){
var result = Number.isInteger( true );
demo1.innerHTML = result;
}
</script>
|
<button onclick="testing2()"> Click me </button>
<p id="demo2"> </p>
<script type="text/javascript">
function testing2 (){
var result = Number.isInteger( false );
demo2.innerHTML = result;
}
</script>
|
Example 5
<button onclick="testing1()"> Click me </button>
<p id="demo1"> </p>
<script type="text/javascript">
function testing1 (){
var result = Number.isInteger( Infinity );
demo1.innerHTML = result;
}
</script>
|
<button onclick="testing2()"> Click me </button>
<p id="demo2"> </p>
<script type="text/javascript">
function testing2 (){
var result = Number.isInteger( -Infinity );
demo2.innerHTML = result;
}
</script>
|
Example 6
<button onclick="testing1()"> Click me </button>
<p id="demo1"> </p>
<script type="text/javascript">
function testing1 (){
var result = Number.isInteger( Number.MAX_VALUE );
demo1.innerHTML = result;
}
</script>
|
<button onclick="testing2()"> Click me </button>
<p id="demo2"> </p>
<script type="text/javascript">
function testing2 (){
var result = Number.isInteger( Number.MIN_VALUE );
demo2.innerHTML = result;
}
</script>
|
https://tonks.tistory.com/166#_javascript_isInteger
이 내용이 도움이 되셨다면, 아래의 하트 버튼을 눌러주세요. *^^*
If this article is helpful to you, please click the heart button below. *^^*