Javascript – Number function

The Number JavaScript object is a wrapper object allowing you to work with numerical values. A Number object is created using the Number() constructor. It can also be used to detect if a String is valid number.

Example – Number() returning valid number

  document.write(Number("123") + "<br>");
  document.write(Number("12.3") + "<br>");
  document.write(Number("") + "<br>");
  document.write(Number("0x11") + "<br>"); // hex
  document.write(Number("0o11") + "<br>");  // octal

Example – Number() returning NaN

  document.write(Number("foo") + "<br>");
  document.write(Number("100a") + "<br>");
Share this article: share on Google+ share on facebook share on linkedin tweet this submit to reddit


Click here to write/view comments