Using parseInt in a function to return an integer or not

this function uses the parseInt function to return a proper integer or an error code if it can't. So this demo should return NaN for the Not an Int (x1235) and The int for the 00001235. I think that NaN stands for Not a Number (but i could be wrong... )


function using_parseint(maybe_an_int) {
  var result_html = document.getElementById("result");
  var parseint_result = parseInt(maybe_an_int);
  result_html.innerHTML = parseint_result;
  return parseint_result;


<div id='result' class='mb-3 alert alert-primary'>..</div>
<button onclick='using_parseint("x1235");' class='btn btn-primary mb-1'>Not an Int (x1235)</button>
<button onclick='using_parseint("00001235");' class='btn btn-primary mb-1'>This is an int, once converted. (00001235)</button>



External Link for Using parseInt in a function to return an integer or not

Other Items in javascript
Page Views

This page has been viewed 185 times.

Search Code
Search Code by entering your search text above.

This is my test area for webdev. I keep a collection of code snippits here, mostly for my reference. Also if i find a good site, i usually add it here.