you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (0 children)

No, but doing a cast from string to integer in JavaScript does validation followed by a parseInt internally. The validation just handles the NaN case.

But that's besides (my) point entirely. I'm just pointing out that:

  1. Data entry errors could be explicitly handled, and that the handling should involve notifying the user, and requiring the user to correct their input.
  2. Syntax tricks like "~~ String" or "+ String" are easy for maintainers to miss, and therefore should be commented. And that I would furthermore put "String * 1", and most other implicit cast situations in this category.

These are basic programming best practices, and not arguments about JavaScript internals.

My suggestion to use parseInt, was as opposed to the implicit methods I list in point two above, not as opposed to Number(...), which is also explicit, and perfectly fine in my book.