Typescript class

TypeScript Class: As we discussed in earlier tutorials that TypeScript supports object-oriented programming concepts like classes, interfaces, etc. Class acts as a blue print or template for creating objects. It provides state and behaviour for its objects. A class is used to encapsulate the data for the object. Syntax: class class_name { //field //constructor //function … Read more

typescript interface inheritance tutorial

Inheritance is one of the OOPs concepts which provides the facility to create a class (new class) from another class (existing class). Existing class is known as Parent/Super/Base class and new class is know as Child/Sub/Derived class. Child class will acquire the state and behavior of Parent class which can be modified or overridden by … Read more

Typescript interface

Dictionary meaning of interface: A point where two systems, subjects, organizations, etc., meet and interact. TypeScript interface: An interface is declared with interface keyword. It is a way of implementing 100 Syntax: interface interface_name { } Example: interface IPerson { firstName:string, lastName:string, sayHi: ()=>string } var customer:IPerson = { firstName:”Ajay”, lastName:”Laddha”, sayHi: ():string =>{return “Hi”} … Read more

TypeScript Union

TypeScript union type: TypeScript Union Type provides the facility to combine one or two types for a variable. The pipe symbol (|) is used to combine the two or more data types. Syntax: var varName: dataType1|dataType2|dataType3 Example: function unionTest(value:string|number):void{ console.log(value); } unionTest(“Jai”); unionTest(123);

TypeScript tuple

TypeScript tuples: Typescript tuple represents a heterogeneous collection of values i.e. it contains a collection of values of different types. Syntax: var tupleName = [value1,value2,value3,…valuen] Example: function tupleTest(values):void{ for (i=0;i

TypeScript array

TypeScript array object: A TypeScript Array object represents a collection of elements of the same type. TypeScript Array Object Properties: Property Description constructor Returns a reference to the array function that created the object. length It reflects the number of elements in an array. prototype It allows us to add properties and methods to an … Read more

TypeScript math

TypeScript math object: A TypeScript Math object provides no. of properties and methods for performing mathematical operations. Math is not a constructor and all the properties and methods of Math are static. TypeScript Math Object Properties: Property Description E \ Euler’s constant and the base of natural logarithms, approximately 2.718. LN2 Natural logarithm of 2, … Read more

TypeScript date

TypeScript date object: A TypeScript Date object represents a date. We can get or set year, month and day, hour, minute, second, and millisecond fields of the object by Date methods. TypeScript Date Object Properties: Property Description constructor It specifies the function that creates an object’s prototype. prototype It allows us to add properties and … Read more

TypeScript boolean

TypeScript boolean object: A TypeScript Boolean object can represents two values “true” or “false”. How to create TypeScript boolean object: By using boolean literals. By using Boolean() constructor. Syntax: Var b1:boolean = true; var b2:boolean = new Boolean(value); Example: function booleanTest(bVar:boolean):void{ console.log(bVar.valueOf()); } var boolean1:boolean=new Boolean(true); var boolean2:boolean=new Boolean(false); var boolean3:boolean=true; booleanTest(boolean1); booleanTest(boolean2); booleanTest(boolean3);

TypeScript string object

TypeScript string object: A TypeScript String object represents a sequence of characters. TypeScript String Object Properties: Property Description constructor It returns a reference to the String function that created the object. length It returns the length of the string. prototype It allows us to add properties and methods to an object. TypeScript String Object Methods: … Read more