Today I Learned - Rocky Kev

TIL Value as Number

POSTED ON:

TAGS:

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:

TIL fancy methods to transform Javascript Objects

You can use Object.entries(), Object.keys(), Object.fromEntries()...

TIL How to steal localData using an XSS attack

But that's just a red flag that opens the door to bigger issues.

TIL Clear-Site-Data

The Clear-Site-Data header clears browsing data (cookies, storage, cache) associated with the requesting website. It allows web developers to have more control over the data stored by a client browser for their origins.