Simple Calculator
Input string expression and calculate the result.
URL Decoder
How it works
This tool takes a string expression like "1+2*3". Wraps it into a function: new Function("return " + input)
. Executes and returns the result.
If the input is invalid, it throws an error.
function runExpression(input) {
if (typeof input !== "string" || input.trim() === "") {
throw new Error("Input must be a non-empty string.");
}
try {
// Use Function constructor to safely evaluate
const result = new Function("return " + input)();
return result;
} catch (e) {
throw new Error("Invalid expression: " + e.message);
}
}
If the input is invalid, it throws an error.