February 2019
Beginner
694 pages
18h 4m
English
If a function has declared that it will return a value, then the compiler can ensure that it does, indeed, return a value by using the noImplicitReturns option. Often, when we are working with a large function, or if we are re-factoring an existing function, we may inadvertently introduce unwanted logic flaws if we are not careful. Consider the following code:
function isLargeNumber(value : number) : boolean | undefined {
if (value > 1_000_000)
return true;
}
Here, we have defined a function named isLargeNumber that can be invoked with a single parameter named value. This function can return either a boolean or undefined. Note that in general, this function should only return a boolean, but for the sake of this discussion, ...
Read now
Unlock full access