//TYPES String, Number, Arrayvartest:String='ahoj';varnum:Number=2;varemployees:String[]=["ferko","jozko","anicka"];employees.push("koloman");//INTERFACES - object of predefined typesinterfaceSuperHero{realName:String;superName:String;}varsuperman:SuperHero={realName:'Clark Kent',superName:'SuperMan'}varspiderman:SuperHero={realName:'Niekto',superName:'SpiderMan'}//ARRAY OF INTERFACESvarsuperHeroes:SuperHero[]=[];superHeroes.push(superman);superHeroes.push(spiderman);console.log(employees);console.log(superHeroes);//LET operator - variables defined with let in blocks dont change values of variables outside of blockletsampleLet=123;if(true){letsampleLet=456;}console.log(sampleLet);//will be 123varsampleVar=123;if(true){varsampleVar=456;}console.log(sampleVar);//will be 456//LOOPSvarrandArray=[4,5,6];for(varvalinrandArray){console.log(randArray[val]);}//FUNCTIONSvargetDiff=function(num1:number,num2:number,num3?:number):number{if(typeofnum3!=='undefined'){returnnum1-num2-num3;}returnnum1-num2;}console.log(getDiff(5,2));console.log(getDiff(5,2,1));//... means there is unkown count of paramaters//reduce calls the specified callback funct ion for all elements in array. return value of callback //function is accumulated result and is used as an argument to next call of callback functionvarsumAll=function(...nums:number[]):number{returnnums.reduce((a,b)=>a+b,0);//console.log(sum);}console.log(sumAll(1,2,3,4,5));//CLASSES//static - shared to all animal objectsclassAnimal{publicfavFood:string;staticnumOfAnimals:number=0;//if i define type of parameter (private/public) it is autoassigned to that variable where constructor is used//so i dont need to do this.name = nameconstructor(privatename:string,privateowner:string){Animal.numOfAnimals++;}ownerInfo(){console.log(this.name+" is owned by "+this.owner);}statichowManyAnimals():number{returnAnimal.numOfAnimals;}private_weight:number;//get and set, so we can assign value to private propertygetweight():number{returnthis._weight;}setweight(weight:number){this._weight=weight;}}varspot=newAnimal("Spot","Doug");spot.ownerInfo();spot.weight=100;console.log("Spot weight is "+spot.weight);console.log("number of animals is "+Animal.howManyAnimals());classDogextendsAnimal{constructor(name:string,owner:string){super(name,owner);Dog.numOfAnimals++;}}vargrover=newDog("Grover","Jimmy");console.log("number of animals is "+Animal.howManyAnimals());//GENERIC FUNCTIONS//when we want to work with multiple datatypes in similar wayfunctiongetType<T>(val:T):string{returntypeof(val);}console.log(getType('string'));console.log(getType(4));//GENERIC CLASSESclassGenericNumber<T>{add:(val1:T,val2:T)=>T;}varaNumber=newGenericNumber<number>();aNumber.add=function(x,y){returnx+y;};varaStrNum=newGenericNumber<string>();aStrNum.add=function(x,y){returnString(Number(x)+Number(y));};aNumber.add(5,4);aStrNum.add("5","6");//STRUCTURINGvarvals={x:1,y:2,z:3};var{x,y,z}=vals;console.log(x);//TEXTvarmultiString=`I go on
for many lines`;document.write(multiString);document.write(`<b>${multiString}</b>`);