Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

309
Visualizações
req.params returns NaN in the error string returned if I try to check its typeof !== number by passing it a parseInt

I need to pass the value of the req.params as a property value to the error object but it returns NaN, I know it's because I've previously parsed the req.params from being a String to being a Number, but I can't find a way to return it the value that ceases to meet the following conditions

const express = require("express");
const app = express();
const port = 8080;
const frase = "Hola mundo como estan";

app.get("/api/letras/:num", (req, res) => {
  const parseadoParams = parseInt(req.params.num);
  parseadoParams === 0 &&
    res.json({
      error: `the parameter ${parseadoParams} is out of range`
    });

  //HERE IS THE PROBLEM, IN THE TYPEOF

  typeof parseadoParams !== "number" &&
    res.json({
      error: `the parameter ${req.params.num} is not a number`,
    });
  if (parseadoParams < frase.length) {
    res.json({
      letra: frase.split(" ").join("")[parseadoParams - 1]
    });
    // Spaces included
    // res.json({letra: frase.charAt(req.params.num - 1)});
  } else {
    res.json({
      error: `the parameter ${parseadoParams} is out of range`
    });
  }
});
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda