Menu

gitpiper

isNumber javascript Code Snippet in 2023

typemathbeginner

Last Updated: 27 May 2023

Checks if the given argument is a number.

  • Use typeof to check if a value is classified as a number primitive.
  • To safeguard against NaN, check if val === val (as NaN has a typeof equal to number and is the only value not equal to itself).
const isNumber = val => typeof val === 'number' && val === val;
isNumber(1); // true isNumber('1'); // false isNumber(NaN); // false

javascript snippet similar to isNumber For You in May 2023

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️

© 2023 GitPiper. All rights reserved

Rackpiper Technology Inc

Company

About UsBlogContact

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️