In JavaScript, you can use eval() for that, make e total equation in string then pass this string to eval(), like
let num1 =(Math.floor(Math.random() * 5000)).toString();
let num2 = (Math.floor(Math.random() * 5000)).toString();
let operator= ['+', '-','*','/'];
let op = operator[Math.floor(Math.random() * 3)];
let str = num1 + op + num2;
//So this string for evaluate.
let res = eval(str);// compare result with this result