In this blog we will discuss about how to use if else condition in TypeScript .

An if-else statement allows you to control the execution of statements based on conditional expression results. An if statement may contain multiple else and if clauses, as well as one else clause at the end. If the statement’s condition is true, the if clause executes one or more statements.

When the preceding condition or conditions are false, the else if clause is executed. If the condition of an else if clause is true, the statement or statements within it are executed.
When all previous conditions are false, the else clause is executed.

One if statement may be included in a block of statements that also contains an if, else if, or else clause in another if statement. Nested if statements are what this is known as.

Syntax :

if (condition)
statement1
[else
statement2]

The if..else statement is used in TypeScript in the example that follows.

Example :

class Greeter {
check_vowel(e: string): number {
if (e == ‘a’ || e == ‘e’ || e == ‘i’ || e == ‘o’ || e == ‘u’)
return1;
return0;
}
}
window.onload = () => {
var n: string;
n = prompt(“Enter a Char”).toLowerCase();
if (n.length == 1) {
var greeter = new Greeter();
var result: number;
result = greeter.check_vowel(n);
if (result == 1) {
alert(“Character is vowel ->” + n);
} else {
alert(“Character is not vowel ->” + n);
}
} else {
alert(“Eneter a charcter not a string”);
}
};

For any Help or Queries Contact us on info@crmonce.com or +918096556344