Static typing and dynamic typing are two different approaches to how types are handled in programming languages.
Static typing:
-
In static typing, variable types are explicitly declared and checked at compile time.
-
The data types of variables are known at compile time, which helps catch type-related errors early in the development process.
-
Examples of statically-typed languages include Java, C, and C++.
Dynamic typing:
-
In dynamic typing, variable types are determined at runtime.
-
Variables can hold values of any type, and type checking is done at runtime.
-
Dynamic typing allows for more flexibility and easier prototyping.
-
Examples of dynamically-typed languages include Python, JavaScript, and Ruby.
In summary, the main difference between static and dynamic typing is when type checking occurs - at compile time for static typing and at runtime for dynamic typing.