December 2017
Beginner
372 pages
10h 32m
English
JavaScript is a very flexible language and one of the flexibilities it provides is that every parameter in a function is optional. You can call a function that accepts a parameter and not pass any parameter to it, and JavaScript will still not complain. On the other hand, in TypeScript, all the parameters are required until explicitly defined as optional.
In the following example we have a parameter, length, which is optional:
function Book(title: string, length?:number){}
As you can see in the preceding code snippet, the only syntax change required to make a parameter from mandatory to optional is to add a question mark (?) after the parameter name. One thing to note is that optional parameters are only ...
Read now
Unlock full access