How to check if a value is a number in TypeScript

1 Answer

0 votes
const value = 48;

if (typeof value === 'number' && !Number.isNaN(value)) {
  	console.log('value is a number');
} else {
  	console.log('value is not a number');
}

   
   
   
   
/*
run:
   
"value is a number"
   
*/

 



answered May 25, 2022 by avibootz

Related questions

...