Last active
May 4, 2017 15:04
-
-
Save sivaprabug/7f8ab8995fee93f3f14461d6afef6325 to your computer and use it in GitHub Desktop.
Confusing string/number with parseInt() Using JavaScript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <title> Confusing string/number using JavaScript</title> | |
| <h1 align="center"><u> Confusing string/number with parseInt() Using JavaScript</u></h1> | |
| </head> | |
| <body> | |
| <script type="text/javascript"> | |
| // var value = 128; | |
| // var value = 200; | |
| var value = "64e"; | |
| console.log('value', valueVal = value); | |
| console.log(typeof(value)); | |
| value = parseInt(value, 10); | |
| console.log('value', valueVal = value); | |
| console.log(typeof(value)); | |
| if (((/^\d+$/.test(value) && value >= 0 && value <= 128))) { | |
| console.log('true'); | |
| } else { | |
| console.log('false'); | |
| } | |
| </script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment