I have found a code for checking whether string is numeric. And it works fine. But I am not getting how is it working. Can anyone explain it.
str = "12132344", str1="abcd", str2="12213234.132332"
/^[\d]+(\.[\d]+){0,1}$/ === str #=> true //perfect
/^[\d]+(\.[\d]+){0,1}$/ === str1 #=> false //perfect
/^[\d]+(\.[\d]+){0,1}$/ === str2 #=. true //perfect
when i change the comparison like below:
str === /^[\d]+(\.[\d]+){0,1}$/ #=> false
str1 === /^[\d]+(\.[\d]+){0,1}$/ #=> false
str2 === /^[\d]+(\.[\d]+){0,1}$/ #=> false
Also I found alternate way to do this by using match.
Can anyone explain what is (===) operator doing here? How it works? Is there any other alternate way?