Hi all. I wonder about this in executing a function with if:
Function A (value){
If(value ==){
Return true;
} else return false;
}
It always return false even if I passed value as .
Anyone can enlighten me? Since I am a beginner in Java so I do hope a simple explanation. Thank you so much.
try to change the == to === this might work , because when you use == it compares the data type not the value of the variable . Hopefully this makes sense
Thank you, @Naomi. Might you help me with which method or what I can do in this situation to express: if passed argument returns an empty array, it will return true?
comparing arrays doesn’t work with comparison operator
you need to
check if it is an array
check if it is an empty array
can you imagine how to do that?
for comparing arrays, you can’t use comparison operator. You can check by doing something like [1, 2, 3] === [1, 2, 3], it will return false. Weird, right? but that’s how it behaves
A different way would be to check by stringifiying, like JSON.stringify([1, 2, 3]) === JSON.stringify([1, 2, 3]), this return true.