-
Book Overview & Buying
-
Table Of Contents
The JavaScript Workshop
By :
TypeScript is an interesting and important alternative to the JavaScript language. A superset of the JavaScript language, TypeScript was developed by Microsoft and was released sometime in 2014. It is very similar to JavaScript but has a feature that is very important to some: strict typing with type inference.
Strict typing is where a variable has a fixed type. This may be a number, a string, or a Boolean. By being strictly typed, a variable is unable to contain a value of any other type. This prevents a number of bugs in your system.
Let's look at a JavaScript problem.
A developer builds a function that accepts two numbers and adds them together:
function add(a, b) {
if (a && b && a + b) {
return a + b;
} else {
throw "invalid parameters passed to 'add' function";
}
}
Now, the developer has thought to check the parameters, first,...