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 - JavaScript Tutorial
From the course: JavaScript: Best Practices for Functions and Classes
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.