Please explain a little bit on this topic. I have went through some articles but I have not satisfied with their explanations.
CodePudding user response:
The empty string ("") returns falsy. An easy way to understand this is by using the logical AND operator
The logical AND operator
If the first object is falsy, it returns that object
console.log('' && 'hello') // falsy && 'hello' --> returns falsy empty string ('')
console.log('hi' && 'hello') // truthy && 'hello' --> returns 'hello'
In the first
console.log()
the empty string is a falsy value and so it returns the empty string.In the second
console.log()
the non-empty string is a truthy value and so it returns the second stringhello