How to check if a string is a valid number in JavaScript
Hi everyone! I'm a beginner in JavaScript and writing a small calculator application. The user enters values into text fields, and I need to make sure the entered data is numbers before performing mathematical operations.
The problem is that I can't figure out a reliable way to check. I used `typeof` — but it shows "string" for everything coming from input. I tried `isNaN()` — but it behaves strangely: `isNaN("123")` returns `false` (good), but `isNaN("12.3abc")` also returns `false`, even though it's clearly not a number! And `isNaN("")` returns `false`, an empty string is considered a number — that's completely confusing.
I also tried `Number(" ")` — it returns 0, which is also confusing. I've heard about `parseFloat` and `parseInt`, but they truncate the string and return a number