DEV Community


Discussion on: JS interview in 2 minutes / Static vs Dynamic typing

rohithv07 profile image
Rohith V

My understanding after reading this post:
Javascript is dynamically type and we can blindly declare a variable without specifying the type and use it as of our needs.
In typescript, we need to give the type for the varible like variableA: number, varibleB: string, so it is statically typed.

A small question : will there be any performance difference between dynamically typed and statically typed as in dynamic typed, the type is decided only at the runtime but in statically type, it is know at the compile time itself

kozlovzxc profile image
Nikita Kozlov Author

Hey 👋 Yep, it's correct.

As for the question, type checks are performed during build time, so it won't affect runtime in any means. Dynamic type checks are more like checks if there is a given property and that's it.

Btw, this only addressing JS/TS, because I've heard that type checks in Python are performed during runtime, which may introduce some overhead.

Also, you can play with typescript in its playground.