switch-case statement is used to run a block of code based on the result of an expression. This program will show you how to use switch-case in typescript.
Readunion type in typescript is used to define a variable that can hold multiple types of values. In this post we will learn how to use union type with examples.
ReadLearn how we can split a string in typescript. We will learn three different ways to split a string in typescript. We can use the split method of string to split a string in typescript.
ReadLearn what is interface in typescript with example. Interface is used to define the syntax of a class to follow.
ReadSuppose you need to work with a local json file in your typescript project. You have this file in your project folder, but how to import it? It is actually pretty easy. In this post, I will show you two different ways to import one JSON file in a typescript project.
ReadType assertion in typescript is used to set the type of a variable and tell the compiler not to infer this. Suppose, you are switching from JavaScript to TypeScript and you know the type of one variable, you can tell the typescript compiler that this is the type this variable will have and you shouldn't do any more type checking for it. This is called "type assertion". Type assertion is used for compile-time checks. You can set type of one variable as number, string or any other type. For example :.
ReadJSON or JavaScript Object Notation is an open standard file format used for transferring data. Parsing JSON data is really easy in Javascript or Typescript. Typescript doesn't have any different methods for JSON parsing. We can use the same JSON.parse method used with JavaScript.
ReadCasting a string to number in typescript requires Javascript methods. Typescript doesn’t provide any specific methods for this conversion. Again, we have a couple of different methods in Javascript that can convert one string to a number. In this post, I will show you different ways to do the conversion.With each example, I am using an array of different strings. Each example will try to convert each of these array elements to numbers.
ReadDifferent ways to add one or more elements to the start, end and middle of an array in TypeScript. We will do that by using push, unshift, index notation, concat and splice methods with examples.
ReadLearn how to iterate over an array in TypeScript in different ways. Learn by using a for loop, using for..in loop, for..of loop and forEach loop.
Read