How to change javascript code from symbol string to non string?

Hello there,

I am trying to convert a symbol inside a string to a symbol without string, I tried a lot but nothing got it works. what method I can use to do that?

here is my code down below:

function operator(op){

var prevValue = 2;
var nextValue = 5;
var operator = op;
var calculation = prevValue operator nextValue;
return calculation;

// how do I convert '+' to + to calculate both numbers??
// how do I get 7 instead of '2+5'??
};

operator('+');

cool I got that now, but how do I convert that + inside a string to get the calculation between prev and nextValue??

Either with string concatenation or with string template literals.

1 Like

I got it and I will do my research on those 2 thank you very much bro :slight_smile: