Why TypeScript?
TypeScript adds static types on top of JavaScript, the compiler checks that your code is internally consistent before it ever runs, catching whole categories of bugs that would otherwise only show up at runtime, in production, in front of a user.
What changed from JavaScript
name: stringdeclares that thenameparameter must be a string, pass anything else and the compiler stops you immediately, instead of the bug surfacing later as a confusing runtime error.): stringafter the parameter list declares the function's return type, if the function body tried toreturn 42instead, that would be a compile error too.- Every valid JavaScript program is already valid TypeScript, you can add types gradually, file by file, instead of rewriting everything at once.
Compile time vs. runtime
TypeScript types only exist while you're writing and compiling code, they're checked once, then stripped away entirely. The JavaScript that actually runs in a browser or Node.js has no idea types ever existed, this is why TypeScript can catch bugs early without slowing down the program itself.
Note: the playground runs TypeScript by stripping the types, full type checking happens in your editor and compiler.