Web APIs

HTMLInputElement.valueAsNumber

Try the free JavaScript compiler

Numeric representation of the current value for supported input types; NaN when no numeric conversion is possible.

Formal Syntax & Structure

javascript syntaxjavascript
input.valueAsNumber

Return Value

number

Numeric value or NaN.

Working Example

Example Snippetjavascript
const i=document.createElement("input");i.type="number";i.value="12";console.log(typeof i.value,i.valueAsNumber);i.value="";console.log(Number.isNaN(i.valueAsNumber));
JavaScript Reference