I know this may be a newbie question, but I’m curious as to the main benefit of eval() – where would it be used best? I appreciate any info.
I know this may be a newbie question, but I’m curious as to the
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The
evalfunction is best used: Never.It’s purpose is to evaluate a string as a Javascript expression. Example:
It has been used a lot before, because a lot of people didn’t know how to write the proper code for what they wanted to do. For example when using a dynamic name for a field:
The proper way to do that would be:
As the
evalmethod executes the string as code, every time that it is used is a potential opening for someone to inject harmful code in the page. See cross-site scripting.There are a few legitimate uses for the
evalfunction. It’s however not likely that you will ever be in a situation where you actually will need it.