TIL Value as Number
POSTED ON:
If you want your input value casted as a number, use valueAsNumber
<script>
const checkMyValueType = (event) => {
console.log(typeof event.target.value) // string
console.log(typeof event.target.valueAsNumber) // number
}
</script>
<input type="number" onkeyup="checkMyValueType(event)" />
double: Returns the value of the element, interpreted as one of the following, in order:
A time value
A number
NaN if conversion is impossible
REFERENCE:
HTMLInputElement - MDN
Related TILs
Tagged: mdn