Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR TYPESCRIPT

typescript if statement

let colour: string = "Blue";

// 	if (condition){
// 		code inside will run if the condition returns true
//  }

if (colour === "Blue"){
    console.log("Blue");
}
else if (colour === "Green"){
    console.log("Green");
}
else {
    console.log("red");
}

// or you could do this 

// let var_name = condition;
// if (var_name){
// 		code inside will run if the condition returns true
// }

let num: number = 10;
let isNumberEven: boolean = num % 2 == 0; // boolean expression
if (isNumberEven){ 
  	console.log("Yes");
}
else {
	console.log("No");
}
 
PREVIOUS NEXT
Tagged: #typescript #statement
ADD COMMENT
Topic
Name
3+1 =