Featured post
- Get link
- X
- Other Apps
How to check null undefined and empty string in javascript
In this blog post, i am going to explain how to check a given string is empty ,undefined or null in javascript. As a programmer ,we need to use string data types in our daily life.So it is better to have a good understanding of string variables in javascript.
let str1 ='';
if (!str1) {
console.log("str1 is empty")
} else {
console.log("str1 is not empty")
} // str1 is empty
str1= undefined;
if (!str1) {
console.log("str1 is empty")
} else {
console.log("str1 is not empty")
} //str1 is empty
str1= null;
if (!str1) {
console.log("str1 is empty")
} else {
console.log("str1 is not empty")
} //str1 is empty
str1= 'Technursery';
if (!str1) {
console.log("str1 is empty")
} else {
console.log("str1 is not empty")
} // str1 is not empty
In the above code,I declared a string variable and assigned the values null, undefined ,empty and Technursery.So based on the condition we get the output.When str1 is null,undefined and empty we got str1 is empty and When str1 is Technursery, we got the output str1 is not empty
Popular Posts
How to Check React Version Installed in Your System by Checking PACKAGE.JSON File and Executing Command from COMMAND PROMPT
- Get link
- X
- Other Apps
Execution failed for task ':react-native-reanimated:externalNativeBuildDebug' solved
- Get link
- X
- Other Apps
Error: Invalid `prisma.$executeRaw()` invocation: fixed using log: ["query"] option
- Get link
- X
- Other Apps
app keeps stopping error solved in android studio emulator using logcat in react native project
- Get link
- X
- Other Apps
ERROR Warning: React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: undefined
- Get link
- X
- Other Apps