[Home] > Snippets  > Languages  > JavaScript  > Validation  >  Check if a number is negative

Check if a number is negative

JavaScript

const isNegative = (n) => Math.sign(n) === -1

// Or
const isNegative = (n) => n < 0

TypeScript

const isNegative = (n: number): boolean => Math.sign(n) === -1

// Or
const isNegative = (n: number): boolean => n < 0

Examples

isNegative(-3) // true
isNegative(8) // false