Typescript_Basic

Run Settings
LanguageTypeScript
Language Version
Run Command
//--1--// const pizzaCost: number = 10; const pizzaToppings: number = 2; function calculateprice(cost: number,toppings: number): number { return cost + 1.5 * toppings; } const cost: number = calculateprice(pizzaCost, pizzaToppings); console.log(cost) //--2--// /* : string */ //--3--// const pizza: number = 5; function offerDiscount(orders: number){ return orders >= 3; } if(offerDiscount(pizza)){ console.log("Discount"); }else{ console.log("No"); } //--4--//
const myName: string = "shubham"; console.log(myName); let surname: string | null = "Boghara"; function removeSurname(): void { surname = null; } console.log(surname); removeSurname(); console.log(surname);
let pizzaSize: string = "small"; function selectSize(size: "small" | "medium" | "large"): void { pizzaSize = size; } selectSize("small"); console.log(pizzaSize);
let sumOrder: (price:number, quantity?: number) => number ; sumOrder = (x,y) => { if(y) { return x*y; } return x; } const sum = sumOrder(25); console.log(sumOrder(25,2)); console.log(sum);
Editor Settings
Theme
Key bindings
Full width
Lines