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

150
Views
Cannot read property 'replace' of null when turning a string value into Number

Hey im trying to convert a string that holds numbers but the string has commas in it and I'm trying to remove those commas as well.

let why = "42,343,324"
console.log(typeof why) // string
let noCommas = parseFloat(why.replace(/,/g, ''));
console.log(noCommas) // 42343324

but when I replace why value with a prop value, it gives me an error saying Cannot read property 'replace' of null

let why = visitsPerPerson
console.log(typeof why)
let noCommas = parseFloat(why.replace(/,/g, ''));
console.log(noCommas)

Output: Cannot read property 'replace' of null

The prop is a string value that holds numbers returned from an API the prop itself doesn't return null but returns a string with numbers in it and can verify when I console log: console.log(visitsPerPerson)

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I re-produced the second code snippet and got expected output:

NaN (Not a Number), which is correct and the expected result for "visitsPerPerson".

Did I understand something wrong?

let why = "visitsPerPerson";
console.log(typeof why); // string
let noCommas = parseFloat(why.replace(/,/g, ''));
console.log(noCommas); // NaN (Not a Number, which is correct)

about 4 years ago · Juan Pablo Isaza 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!