Static vs dynamic typing

This is part of the Semicolon&Sons Code Diary - consisting of lessons learned on the job. You're in the types category.

Last Updated: 2021-05-16

Ruby 2 is dynamically (and strongly -- which is a separate issue) typed, whereas Typescript is statically typed.

Example of static typing:

// Types of variables are restricted

let name: string = "Susan",
    age: number = 25,
    hasCode: boolean = true;

Example of dynamic typing:

# Types are free to change
name = "Susan"
age = 25
hasCode = true

name = 25

When we talk about dynamic typing, we talk about a mechanism where the type of a variable can change and be resolved on the fly at the exact moment it gets parsed by the interpreter.

Resources