- Allow instances of a type to have extra properties
interface User {name: string; age: number}
const jeff = {name: 'Jeff', age: 18, gender: 'male'};
const user: User = jeff; // OK
Types are determined at compile time
- Require to declare data w/ type annotation or type inference
string name = "Jeff"; // type annotation
var name = "Jeff"; // type inference
- Disallow to re-assign variable w/ different types
string name = 3; // ⛔ Compile error
string name = "John"; // ✅ OK
🌗 Opposite: Dynamically typed
Types are determined at runtime
- Don't require to declare data types
name = "Jeff"
- Allow to re-assign variable w/ different types
name = 3; // ✅ OK
🌗 Opposite: Statically typed
- Characteristics:
- Immutable: size is fixed and elements can not be modified => less memory and iterate faster than list, array,
- Can contain elements of different data types.
- Operations: indexing, slicing, membership test.
- Use cases:
- Return multiple values from private and internal utility methods w/o define a new type (POCO class/interface...)
- Asign multiple variables at the same time.
- Swap two variables w/o using additional temprory variable.
An entity which supports all the operations generally available to other entities, such as being passed as an argument, returned from a function, modified, assigned to a variable.
- Treat function as first class citizen -> can be passed as an argument
- The argument function can be a ananymous function
- Use cases:
- Callback
- Used along w/ collection operations such as map(), where(), and reduce(), etc