Javascript: How to check if a string is empty?

Possible Duplicate:
What is the best way to check for an empty string in JavaScript?

I know this is really basic, but I am new to javascript and can't find an answer anywhere.

How can I check if a string is empty?


我检查长度。

if (str.length == 0) {
}

If you want to know if it's an empty string use === instead of ==.

if(variable === "") {
}

This is because === will only return true if the values on both sides are of the same type, in this case a string.

for example: (false == "") will return true, and (false === "") will return false.


这应该工作:

if (variable === "") {

}
链接地址: http://www.djcxy.com/p/27514.html

上一篇: 如何检查JavaScript中的输入是否为空?

下一篇: Javascript:如何检查一个字符串是否为空?