From the course: JavaScript: Best Practices for Functions and Classes

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Avoid eval

Avoid eval - JavaScript Tutorial

From the course: JavaScript: Best Practices for Functions and Classes

Start my 1-month free trial

Avoid eval

- [Instructor] Eval is a JavaScript keyword that sounds like a great idea on the surface, but isn't. Eval takes an expression as an argument and returns the result. In theory, it's a useful tool that could serve as a shortcut in a number of situations, but unless you're an experienced JavaScript developer with a very specific use case, you should avoid using eval. One of the big drawbacks of eval is the potential security issues it presents. It's often tempting to use eval in conjunction with user-provided data, which can present security issues. In addition, parsing code on the fly can impact your app's performance. Fortunately, there are straightforward alternatives for most uses of eval. The app dot JS file for this video includes the selection variable, which is a placeholder for a user selection. I also have an object that contains values that map to whichever of the three options the user has picked. I then…

Contents