[英]Node.js - does not detect the same data
I'm comparing two strings I get from the SQL database and the html form but the equals don't work.我正在比较我从 SQL 数据库和 html 表单中获得的两个字符串,但相等不起作用。
if (database.recordset[0].name=== myString) {
console.log("work");
}else{
console.log("dont work");
}
OUTPUT输出
dont work
Read data with console使用控制台读取数据
console.log(database.recordset[0].name);
console.log(myString);
OUTPUT:输出:
asdasd
asdasd
But if not working...但如果不工作...
EDIT编辑
I used this:我用过这个:
console.log(typeof database.recordset[0].name);
console.log(typeof myString);
OUTPUT输出
string
string
When comparing MySQL and other variables the main difference between "==" and "===" operator is that formerly compares variable by making type correction eg if you compare a number with a string with numeric literal, == allows that, but === doesn't allow that, because it not only checks the value but also type of two variable, if two variables are not of the same type "===" return false, while "==" return true.在比较 MySQL 和其他变量时,“==”和“===”运算符之间的主要区别在于,以前通过进行类型校正来比较变量,例如,如果将数字与带有数字文字的字符串进行比较,== 允许这样做,但是 = == 不允许这样做,因为它不仅会检查两个变量的值,还会检查两个变量的类型,如果两个变量的类型不同,“===”返回 false,而“==”返回 true。
<script>
// In R.H.S. string "3" is converted into
// number 3, hence returns true.
document.write(9 == "9");
// used for next line
document.write('<br>')
// Here no type conversion takes place,
// hence returns false
document.write(9 === "9");
here is another example with strings这是另一个字符串示例
// Here LHS is a string literal whereas // RHS is a string object, // due to type conversion of string object into // a string literal, it returns true. document.write("GeeksforGeeks" == new String("GeeksforGeeks")); // used for next line document.write('<br>') // No type conversion takes place document.write("GeeksforGeeks" === new String("GeeksforGeeks"));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.