function function_name()
{
var a=1;
var b=2;
return {a, b}
}
let {p1, q1} = function_name()
Why do I get an error message about the values of p1, q1 as undefined? However, the below code gives the expected results:
var o = {p: 42, q: true};
var {p, q} = o;
console.log(p); // 42
console.log(q); // true
Can any one please explain the difference between the two code examples?