Dhruv Tyagi Dhruv Tyagi -5 years ago 340
jQuery Question

Comparison of two String is not working in script

Actually in my function I have to compare two strings, the one string I fetch through the db and compare to the

string but it's not working..
Here is my Code:

order.items.forEach(function(entry) {
result += '<tr>'
+ '<td>'+'<font size=2>'+ a++ + '</font>'+ '</td>'
+ '<td>' +'<font size=2>'+ entry.title + '</font>'+ '</td>'
+ '<td>' +'<font size=2>'+ entry.quantity + '</font>'+'</td>'
if(entry.personalization == 'null') //here is the problem
+ '<td>' +'<font size=2>'+ 'No Personalization' + '</font>'+'</td>'
+ '<td>' +'<font size=2>'+ entry.personalization + '</font>'+'</td>'

+ '</tr>';

result +='</table>';


Answer Source

As mentioned in your question, if one string i fetched by you and the other string is "null", It is a clear question of string comparison and not checking null...

Javascript has localeCompare() method to compare strings..

You should use


or its inverse

var n = "null";

this function returns boolean.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download