Skip to content

Instantly share code, notes, and snippets.

@sivaprabug
Last active May 4, 2017 15:04
Show Gist options
  • Select an option

  • Save sivaprabug/7f8ab8995fee93f3f14461d6afef6325 to your computer and use it in GitHub Desktop.

Select an option

Save sivaprabug/7f8ab8995fee93f3f14461d6afef6325 to your computer and use it in GitHub Desktop.
Confusing string/number with parseInt() Using JavaScript
<!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