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

310
Views
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
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!