Javascript 实现Equals运算符的困难

Javascript 实现Equals运算符的困难,javascript,parse-platform,logical-operators,Javascript,Parse Platform,Logical Operators,我有两个Parse-generatedobjectId字符串,我知道它们是相等的,因为我打印并读取它们,它们是相同的 它们是requestedUserId和requestingUserId 我已经试着像评论中提到的那样检查看不见的字符 console.log('"' + requestedUserId + '"') console.log('"' + requestingUserId + '"') 然而,正如人们所怀疑的那样,它们打印出来的数据是相等的 下面的代码从不运行,它跳转到else语句

我有两个Parse-generated
objectId
字符串,我知道它们是相等的,因为我打印并读取它们,它们是相同的

它们是
requestedUserId
requestingUserId

我已经试着像评论中提到的那样检查看不见的字符

console.log('"' + requestedUserId + '"')
console.log('"' + requestingUserId + '"')
然而,正如人们所怀疑的那样,它们打印出来的数据是相等的

下面的代码从不运行,它跳转到
else
语句。我的逻辑有问题吗,或者其他显而易见的问题吗

Parse.Cloud.beforeSave("FriendRequest", function(request, response) {

  var requestedUserId = request.object.get("to")
  var requestingUserId = request.object.get("from")

  console.log('"' + requestedUserId + '"')
  console.log('"' + requestingUserId + '"')     

  // One cannot request oneself
  if (requestedUserId == requestingUserId) {
    console.log("can't send a request to yourself")
    response.error("can't send a request to yourself");

  } else {
    (...)
  }
});

根据我的评论,我建议您检查两个字符串的
长度
,而不是依赖于控制台中的可见性

var str1='abc123';
var str2='abc123'+String.fromCharCode(0);
console.log('''+str1+'',str1.length);
console.log(“'+str2+”,str2.length);

console.log(str1==str2)嗯,你怎么这么肯定字符串是一样的,假设计算机认为它们不是尖锐的,因为我选择不包括我的
控制台。打印字符串的log
语句语法错误将导致代码根本无法运行。您是否检查了控制台中看起来相同的两个字符串的
长度
,Xotic750询问您是否检查了每个字符串的
.length
。有你?如果它们相等,则可能需要迭代一个字符串中的字符,并将每个字符与第二个字符串中相同索引处的字符进行比较。