You can use the strict equality operator (===) to check whether a string is empty or not.
The comparsion str === "" will only return true if the data type of the value is string and it is not empty, otherwise return false as demonstrated in the following example:
Use the
===OperatorYou can use the strict equality operator (
===) to check whether a string is empty or not.The comparsion
str === ""will only returntrueif the data type of the value is string and it is not empty, otherwise returnfalseas demonstrated in the following example:As you can see the values null, undefined, false returns false in the comparision, because they are special values.
need an explanation for this answer? contact us directly to get an explanation for this answer