Menu

gitpiper

isNumber javascript Code Snippet in 2024

typemathbeginner

Last Updated: 14 March 2024

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 March 2024

Subscribe to our Newsletter

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

© 2024 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! ✌️