为什么返回的是真而不是假?

时间:2020-06-15 11:16:28

标签: if-statement equals

在我的一生中,我不知道为什么当我使用的变量不相同时,此代码会恢复为真。

 deleteComment(comment){
      console.log(this.user.id)
      console.log(this.$route.params.id) 
        if('this.user.id', '==', 'this.$route.params.id'){
              db.collection("comments").doc(comment.id).delete();
              console.log("Document successfully deleted!")
            } else {
              console.log('no can do')
            }
         }
       }
   }

说this.user.id = a和this。$ route.params.id = b。

我运行此代码console.log每个日志都有正确的值。但这仍会删除该文档,但不应删除。

根据我的理解,如果(a == b)不正确,那么它应该下降到代码的其他部分吗?使用Vue

1 个答案:

答案 0 :(得分:0)

询问长度是否为真字符串,将始终导致true

我读这句话是

if (true, true, true) {
   // Something will always happen
} else { // This will never run } 

你的意思是

if (this.user.id === this.$route.params.id) {
   // Something will sometimes happen
}