// Optional parameter
function foo(x?: number) {
console.log("x : "+ x);
}
foo();
foo(6);
function functionName(par1: number, par2?: number) {
}
function multiply(a: number, b: number, c?: number): number {
if (typeof c !== 'undefined') {
return a * b * c;
}
return a * b;
}
function newsArticle(options: newsArticleOptions) {
const {
showHeadline = true,
showDate = true,
articleType = "World"
} = options;
}
// Use like this
newsArticle({ articleType: "Tech" });
// Of course, don't write JavaScript without TypeScript
interface newsArticleOptions {
showHeadline?: boolean
showDate?: boolean
articleType?: articleType
}
type articleType = "Tech" | "World" | "Sports"