if (userRecord === false) { // didn't work
console.log("inside if userRecord === false");
models.UserAccount.create({
username : req.body.username,
password : hashedPassword
})
if (!userRecord) { // worked
console.log("inside if !userRecord");
models.UserAccount.create({
username : req.body.username,
password : hashedPassword
})
Above code uses Sequelize and tests if a record was found. I assumed === false would be true if Sequelize didn’t return anything, but it never triggers, only !userRecord works.
I know the ! operator is good for flipping values like on a checkbox. But why is “Not true” here different from False?
PG/MySQL/etc use null for nonexistence, so I assume Sequelize takes that and converts it to a JS null. false is a perfectly acceptable value in a DB column (it would have a boolean type), whereas null value for a field is (with respect to RDBMs that Sequalize deals with) special. I assume that field will never be false, because that means the [whatever SQL implementation] type of the relevant column would be boolean; you’re checking if the lookup returns null, not whether it is false
(Edit: which all makes using ! slightly dangerous in some regards but hey it’s JS )