DEV Community

Discussion on: You should stop using `parseInt()`

 
coolprofessor profile image
coolprofessor

Potentially, but can't you check the string for functions using 'str.includes("()")'?

Thread Thread
 
blackr1234 profile image
blackr1234 • Edited

If you are referring to checking if the string contains function call by searching for "()", no it won't work because there are way too many scenarios. Consider a case when there are spaces in between the parenthesis, e.g. foo( ) and your code will then allow it to run. It will be better if you only allow whitelisted characters. However, it will still take unnecessary effort and still potentially cause the program to hang (if you are going to search/parse the whole string which can be very long). So just use the built-in functions that work just fine and don't reinvent the wheel, which is something stupid.