class Greeting
{
greet():void
{
console.clear();
console.log("Hello ..!!!");
console.clear();
}
}
// This is a single line comment which creates an Instance Object
var obj = new Greeting();
obj.greet();
let myAdd = ( x: number , y: number): number => { return x+y; };
console.log(myAdd(23,21));
// first two "number" defines type for parameters 'x' and 'y'
// third "number" defines `return type` of function
//We can define optional parameter by adding “?” so that anyone calling that function may or //may not pass value for that variable. Optional parameters do not exist in JavaScript and
// hence those will not be handled.
var addFunction = (n1: number, n2: number, n3?: number) : number => {
//observe "?" in parameter n3
//Optional parameter has to be the last parameter in the list
if (typeof n3 !== 'undefined') {
return n1 + n2 + n3;
}
return n1+n2;
}
var sum = addFunction(10, 20); //output: 30
console.log(sum);
var addFunction = (n1: number, n2: number, n3: number = 30) : number => {
//observe parameter n3 has default value
return n1+n2+ n3;
}
var sum = addFunction(10, 23230); // output: 60
console.log(sum);
//
let items = [0, 1, null, 'Hi'];
items.forEach((item) => { console.log(item)});
items.forEach((number, index, array) => {
console.log(array);
});
interface Point2D {
x: number;
y: number;
}
var point2D: Point2D = { x: 0, y: 10 }
console.log(point2D.x+point2D.y);
// any
// It implies that the variable can take any type of value, which denotes a dynamic type.
var value: any = 30; //can take string, number, boolean anything
console.log(value);
//Built-in
//Built-in types in Typescript are number, string, boolean, null, undefined, and void.
var value1: string = "john"; //can take only string values
console.log(value1);
interface Todo
{
name:string,
taskdecription:...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.