I need to evaluate the result of the following expression:
startCell = 50
size = 9
cnt = 1
var res = startCell + (size * cnt) + cnt
var res = eval(startCell + (size * cnt) + cnt);
There is nothing wrong with the code you posted. Proof: http://jsfiddle.net/Q8M7S/
The cause of your problem is in the code we can't see. Something is turning
cnt into a string, but
size are still numbers. If they were all strings, you'd get
5091 instead of
It could be that
cnt is being initialized to a string:
startCell = 50 size = 9 cnt = "1"
cnt = 1 cnt += ""
There are a lot of ways it could happen, and no one can know for sure without seeing the code. I suggest you look for every line that modifies
cnt between the time you initialize it and the time you use it.
Also, be warned about
eval. It's potentially dangerous when used incorrectly, and it's terrible for performance. You should avoid using
eval when you can, at any skill level.