Navigate back to the homepage

how to check empty string in typescript?

Infinitbility
TypeScript
July 20th, 2022 · 1 min read
how to check empty string in typescript?

check an empty string in typescript

To check an empty string in typescript, use the if..else statement just pass and put your string variable in an if condition if it’s empty it will go to the else statement.

Today, I’m going to show you How do i check an empty string in typescript, as mentioned above, I’m going to use the use if..else statement to check the typescript empty string.

Let’s start today’s tutorial how do you check an empty string in typescript?

In this example, we will do

  1. take an example of an empty string variable
  2. use the if..else statement
  3. send the output in the response
1let str: string = "";
2
3// ✅ check an empty string in typescript
4if(str){
5 console.log("str is not empty");
6} else {
7 console.log("str is empty");
8}
9
10// 👉️ str is empty

In the above typescript example, we have taken the sample empty string variable, use the if..else statement, and print the output in the console.

Note: To bypass spaces in the string using the trim() method, it will remove both sides extra spaces from the string.

I hope it helps you, All the best 👍.

Follow me on Twitter

Join our email list and get notified about new content

No worries, I respect your privacy and I will never abuse your email.

Every week, on Tuesday, you will receive a list of free tutorials I made during the week (I write one every day) and news on other training products I create.

Looking For React Native Tutorial?

we are trying to create the best Tutorial for react native developers.

When you want a daily updates about React Native Tutorial or infinitbility update subscribe to our newsletter.

Read React Native Tutorial

Request New Tutorial or Article on mail [email protected]

Guide book

Guidebook: The Javascript Monorepo Photoshop Guide

Tutorials

Categories

More articles from Infinitbility

how to stringify json object in typescript?

how to stringify json object in typescript?

TypeScript, stringify JSON object example with the step-by-step guide.

July 20th, 2022 · 1 min read
how to convert array to string in typescript?

how to convert array to string in typescript?

TypeScript, convert array to string example with step-by-step guide.

July 19th, 2022 · 1 min read
© 2020–2022 Infinitbility
About
Link to $https://medium.com/infinitbilityLink to $https://www.facebook.com/InfinitbilityLink to $https://github.com/infinitbilityLink to $https://twitter.com/infinitbilityLink to $https://www.buymeacoffee.com/infinitbilityLink to $mailto:[email protected]