DEV Community

Discussion on: Pure dynamic Type check in javascript

Collapse
 
4r7d3c0 profile image
4r7d3c0 • Edited

Hi Dam thanks for this article, it's a good read.

DATE: (data)=>(typeof data)==='date', -> This works with your own typedef but not with typeof :)

I thought about dynamic type checking and it's quite different from the static one -- whereas the static really ensures safety BECAUSE the program won't even exist if there are inconsistencies in types, the dynamic type checking is only useful to provide understandable errors and "fail early" rather than ensure true safety like in the case of the static one. The program will still throw at runtime, but only early and with a human-readable message.