Difference between null and undefined (explained in 5 seconds)
null
says
there is absolutely nothing.
undefined
says
there should be something but I have nothing.
This is why the following function returns undefined
when the argument is passed nothing because it means the function needs something but it has nothing.
function foo(bar){
return bar;
}
console.log(foo()); // undefined
Brainteaser: So, if you query a filtered list of Person
from database and there is no Person
data. What should function return null
or undefined
?