eval is not always evil

Marcos Neves
vuejs-tips
Published in
1 min readJun 15, 2017

Simple expression calculator as tip #26

Eval has always been considered evil, but in this case we're removing every character except for numbers, parenthesis and math operators + - * /.

Type any math expression

The eval must be inside a try/catch in case the expression is invalid.

We are using computed properties to parse the input and to eval the expression.

What evil things you've been doing with eval?

--

--

Marcos Neves
vuejs-tips

Ancient Brazilian web developer, from php, through Rails to Javascript, Vue.js enthusiast to React.