The first method is to delete return keywords and the semicolon:
var expression = '2+2+2';
var result = eval('(' + expression + ')')
alert(result);
note the '(' and ')' is a must.
or you can make it a function:
var expression = 'return 2+2+2;'
var result = eval('(function() {' + expression + '}())');
alert(result);
even simpler, do not use eval:
var expression = 'return 2+2+2;';
var result = new Function(expression)();
alert(result);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…