JavaScript Coder

TypeScript

Harness the Power of TypeScript Dictionaries: An In-Depth Tutorial

In programming, a dictionary is like a real-life dictionary, where you look up a ‘word’ (key) to find its ‘meaning’ (value). TypeScript, like JavaScript, doesn’t have a built-in Dictionary type, but we can use an object to achieve the same functionality. Why do we use it? Simply because it’s a very efficient way to store and retrieve data where the order is not important, but the link between keys and values is.

Continue Reading →

Typescript Optional Parameters

All parameters of a function are required by default. The parameters of a function should match the type specified by the function signature as well. For Example: function fullName(first:string, middle:string, last:string) { return first+" "+middle+" "+last; } fullName("Mark");//Error parameters middle and last are missing fullName("Mark", null,null);//Error: null is not assignable to string fullName("Mark", undefined,undefined);//Error: undefined is not assignable to string Syntax for optional parameters Here is the code that declares middle and last names to be optional:

Continue Reading →