Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

86
Views
ESLint Uso inesperado de isNaN

Estoy tratando de usar la función global isNaN dentro de una función de flecha en un módulo Node.js pero recibo este error:

[eslint] Unexpected use of 'isNaN'. (no-restricted-globals)

Este es mi código:

 const isNumber = value => !isNaN(parseFloat(value)); module.exports = { isNumber, };

¿Alguna idea de qué estoy haciendo mal?

PD: Estoy usando la guía de estilo de AirBnB.

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Como sugiere la documentación , utilice Number.isNaN .

 const isNumber = value => !Number.isNaN(Number(value));

Citando la documentación de Airbnb:

¿Por qué? El isNaN global obliga a los no números a números, devolviendo verdadero para cualquier cosa que coaccione a NaN. Si se desea este comportamiento, hágalo explícito.

 // bad isNaN('1.2'); // false isNaN('1.2.3'); // true // good Number.isNaN('1.2.3'); // false Number.isNaN(Number('1.2.3')); // true
over 4 years ago · Santiago Trujillo Report

0

FYI, esto no funcionará para IE. Compruebe aquí la compatibilidad del navegador.

over 4 years ago · Santiago Trujillo Report

0

@Andy Gaskell isNumber('1.2.3') devuelve true , es posible que desee editar su respuesta y usar Number() en lugar de parseFloat()

 const isEmpty = value => typeof value === 'undefined' || value === null || value === false; const isNumeric = value => !isEmpty(value) && !Number.isNaN(Number(value));
 console.log(isNumeric('5')); // true console.log(isNumeric('-5')); // true console.log(isNumeric('5.5')); // true console.log(isNumeric('5.5.5')); // false console.log(isNumeric(null)); // false console.log(isNumeric(undefined)); // false
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!