alert('g' - 'a') returns no number. ('NAN').
But I expect to get the difference between ascii as alert(103-97) => alert(6) . Therefore, 6 will be output.
In C, int i = 'g' - 'a' , will give i = 6 .
How to achieve this two-character subtraction in javascript? (easy without much effort, as shown below)
alert("g".charCodeAt(0) - "a".charCodeAt(0)) gives 6.
Appendix: I use this in a chess program.
source share