r/programming • • Jun 28 '21

JavaScript Is Weird

https://jsisweird.com/
329 Upvotes

173 comments sorted by

View all comments

Show parent comments

2

u/flatfinger Jun 28 '21

A compiler may not be able to optimize out type checks completely, but it could generate code which tests whether an object is of expected type, performs operations optimized for that type if so, and otherwise uses code that can handle arbitrary types. Not as big a win as eliminating the type checks, but still pretty big nonetheless.

2

u/StillNoNumb Jun 28 '21

Modern JS compilers already do that, at an overhead much smaller than the typechecking that TS has to do.