1

I'm still not sure if there is any difference in efficiency for this simple use. I know is not needed to get 'px' additionally off with use parseInt. Is there e.g. any plus for using Number() in this case? What problems could happen with these solution or what is more efficient for memory.

  • 2
    I’d prefer _`parseFloat`_. `15.6px` is a valid CSS value. – Sebastian Simon Feb 20 '22 at 14:26
  • 1
    `Number()` won't work unless you strip off the "px" before calling it. I'm pretty sure, though I haven't seen it documented, that the behavior of `parseInt()` and `parseFloat()` was originally intended for exactly this purpose. – Pointy Feb 20 '22 at 14:28
  • It's up to you. I list your options and the various considerations you might want to take into account in [this answer](https://stackoverflow.com/questions/28994839/why-does-string-to-number-comparison-work-in-javascript/28994875#28994875). – T.J. Crowder Feb 20 '22 at 14:32

0 Answers0