Related to coerce and default values in JavaScript, given this code:
function greet(name){
name = name || '';
console.log("Hello " + name);
}
greet();
Not given any name as parameter, we have
- undefined || ' '
And it's known that
Boolean (undefined) coerces to false
Boolean (' ') coerces to false
So we have:
false || false (undefined || ' ' )
Why the 'OR function' is returning the second parameter (' ') instead of the undefined if the undefined is first in the expression?