Typecasting

Protect your application with typecasting.

What is typecasting?

One additional step, for security and data integrity, is to typecast known formats. Since JavaScript is dynamically typed, a value can be any type. By typecasting the value, you can verify that the data matches are what you expect. Recall the previous MySQL example. If the ID came from a variable, it would make sense to typecast it, only if you know it should always be an integer, like this:

Get hands-on with 1200+ tech skills courses.