How to check if an eval name is undefined
I can think of three solutions:
- You can make an assumption that empty m1/m2 means 0, so there will never be an undefined value. This really simplifies things.
- You can use regexp to check first for any occurrence of m1 or m2 in the equation and if it exists then check if is undefined.
- But the best method is to use try...catch.
Try/Catch Example:
try {
eval('12+3+m1');
} catch (e) {
alert(e.message);
}