xxxxxxxxxx
let str = "";
if (Boolean(str))
console.log("This is not an empty string!");
else
console.log("This is an empty string!");
xxxxxxxxxx
let myStr = null;
if (myStr === null || myStr.trim() === "") {
console.log("This is an empty string!");
} else {
console.log("This is not an empty string!");
}
/*
This will return:
"This is an empty string!"
*/
xxxxxxxxxx
// Test whether strValue is empty or is None
if (strValue) {
//do something
}
// Test wheter strValue is empty, but not None
if (strValue === "") {
//do something
}
xxxxxxxxxx
function isNullOrEmpty(str) {
return str === null || str.trim() === '';
}
// Usage example
const myString = null;
const result = isNullOrEmpty(myString);
console.log(result); // Output: true
xxxxxxxxxx
let myStr = null;
if (myStr === null || myStr.trim() === "") {
console.log("This is an empty string!");
} else {
console.log("This is not an empty string!");
}
xxxxxxxxxx
var string = "not empty";
if(string == ""){
console.log("Please Add");
}
else{
console.log("You can pass"); // console will log this msg because our string is not empty
}
xxxxxxxxxx
Use for Empty string, undefined, null,
//To check for a truthy value:
if (strValue) {
// strValue was non-empty string, true, 42, Infinity, [], ...
}
//To check for a falsy value:
if (!strValue) {
// strValue was empty string, false, 0, null, undefined, ...
}
xxxxxxxxxx
if (strValue) {
// strValue was non-empty string, true, 42, Infinity, [], ...
}
xxxxxxxxxx
<?php
/**
* @author : Nanhe Kumar <nanhe.kumar@gmail.com>
* List of all empty values
**/
$testCase = array(
1 => '',
2 => "",
3 => null,
4 => array(),
5 => FALSE,
6 => NULL,
7=>'0',
8=>0,
);
foreach ($testCase as $k => $v) {
if (empty($v)) {
echo "<br> $k=>$v is empty";
}
}
/**
Output
1=> is empty
2=> is empty
3=> is empty
4=>Array is empty
5=> is empty
6=> is empty
7=>0 is empty
8=>0 is empty
**/
?>