Javascript Number Type check if a defined variable is a number

Description

Javascript Number Type check if a defined variable is a number

let a = Number(5.912); 
let b = 4.7; /*from   w w w. ja va  2s  .c  o m*/
let c = ""; 
let d = new Date(); 

if ( typeof a === 'number' ) {
   console.log("a is a Number"); 
} else { 
   console.log("a is not a Number"); 
} 

if ( typeof b === 'number' ) {
   console.log("b is a Number"); 
} else { 
   console.log("b is not a Number"); 
} 

if ( typeof c === 'number' ) {
   console.log("c is a Number"); 
} else { 
   console.log("c is not a Number"); 
} 

if ( typeof d === 'number' ) {
   console.log("d is a Number"); 
} else { 
   console.log("d is not a Number"); 
} 



PreviousNext

Related