Navigate back to the homepage

how to check a variable is undefined in typescript?

Infinitbility
TypeScript
September 5th, 2022 · 1 min read

Hi Friends 👋,

Welcome To Infinitbility! ❤️

To check a variable is undefined in typeScript, use if...else statement it will handle all falsy value like undefined, null, empty and etc.

Let’s see short example to use if...else with variableName to check a variable is undefined in typeScript.

1if(variableName){
2
3}

Today, I’m going to show you How do I check a variable is undefined in typeScript, as above mentioned, I’m going to use the above-mentioned if...else statement.

Let’s start today’s tutorial how do you check a variable is undefined in typeScript?

TypeScript check a variable is undefined example

Here, we will take string variable with some data and use if...else statement to check a variable is undefined.

1let string: string | undefined;
2
3if(string){
4 console.log("string is defined")
5} else {
6 console.log("string is undefined")
7}
8
9// You can also check specific conditions like a string is undefined or not
10
11if(string == undefined){
12 console.log("string is undefined")
13} else {
14 console.log("string is defined")
15}

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 check array is null or not in typescript?

An example of check array is null or not in typeScript with the step-by-step guide.

September 4th, 2022 · 1 min read

how to check array or not in typescript?

An example of check array or not in typeScript with the step-by-step guide.

September 3rd, 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]