How to check if a value is an integer in JavaScript

2 Answers

0 votes
const n = 923247;
 
console.log(Number.isInteger(n));
 
 
 
/*
run:
 
true

*/

 



answered Nov 9, 2019 by avibootz
edited May 18, 2024 by avibootz
0 votes
console.log(Number.isInteger(5)); 
console.log(Number.isInteger(-2)); 
  
console.log(Number.isInteger(3.14)); 
console.log(Number.isInteger(-9.5)); 

console.log(Number.isInteger('345')); 
 
  
  
/*
run:
  
true
true
false
false
false

*/

 



answered Mar 11, 2020 by avibootz
edited May 18, 2024 by avibootz
...