Reading data from input elements

See how we read data from input elements:

    document.getElementById("zipCode") as HTMLInputElement

The as HTMLInputElement construct is basically casting a result into the HTMLInputElement class.

Using as directly is not advisable because it can give you ClassCastException; a proper way to use it is as? HTMLInputElement. This returns null if the class cast fails. And Kotlin will force you to use a Null Safety operator from that very moment.

Get Kotlin Blueprints now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.