Typescript

Data types in ECMA5 or JS :
  1. string
  2. number
  3. boolean
  4. null/undefined – to specify empty of nothing
  5. Object – to specify everything else in JS
  6. any – it is not used manually mostly but inferred by js to those whose type are dynamicaaly defined, the true nature of JS.

function overloading:

function can be overloaded(same name different signature) in javascript the the implementation is one,other function declaration appears above the implemented one, and the implementation one is always called.

Example:

function overload(x:string,y:string)
function overload(x:any[],y: any[])
 function overload(x:(string|any[]),y:(string|any[])){         //here x,y is string or array of any type(number/string)
var len: number=x.length+y.length;
return len;
}

Declaring type for function parameter & normal variable type:

syntax for variable-

variable_name: type;

example-

name: string;

explanation -

type is declared after colon sign(:) after the variable name.

Syntax for function-

function myfunction(x: string,y: number): any{
}

description:

function takes two parameter of types – string & number and return type is any (can be anything -inferred dynamically not recommended but just for example).

Published by

Unknown's avatar

sevanand yadav

software engineer working as web developer having specialization in spring MVC with mysql,hibernate

Leave a comment