I’m going to check if input string is a valid mathematical expression. I have used eval
, Number
and parseFloat
, but none of them worked correctly as shown bellow:
- I expect
eval('1//2')
to identify that the input is NOT valid, but it results in1
which is not correct for me. - I also expect
Number('2.5/6')
to be0.4166666666666667
, but it results inNaN
which is not correct for me. - I also expect
parseFloat('1//2')
to identify that the input is NOT valid, but it results in1
which is not correct for me.