I wrote an if statement using the following data.
const data = {
field: ""
}
const data2 = {
field: "abc"
}
if (data.field && data.field !== data2.field) {
console.log('not in')
}
I was expecting that if condition to return true, but it returns an empty string("") so it is not included in the branch.
As shown below, if it is not an empty string(""), true is returned. Why isn't true if an empty string("") is included in the conditional statement?
const data = {
field: "ccc"
}
const data2 = {
field: "abc"
}
if (data.field && data.field !== data2.field) {
console.log('in')
}