what’s type safety?

tags: learning programming

content

  • type safety means the programming language prevents you from doing operations on a value that’s not valid for its type
  • a type-safe language doesn’t allow you to call a method that does not exist on a type
var a = 1;
var b = "test";
a = a + b;  // this is allowed because js is dynamically typed
a.toUpperCase()  // a is now "1test"
  • if b is another int, the program will crash at runtime, because there’s no toUpperCase method for type int
  • toUpperCase is valid for type string, but not valid for type int

up

down

reference