var varname = 'foo'; // pretend a user input that
var value = 42;
eval('var ' + varname + '=' + value);