Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR TYPESCRIPT

add optional parameters javascript or typescript function

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"
Source by mattferderer.com #
 
PREVIOUS NEXT
Tagged: #add #optional #parameters #javascript #typescript #function
ADD COMMENT
Topic
Name
8+9 =