// Method 1
function obj() {
return { a: 1 };
}
// Method 2
function Obj() {
this.a = 1;
}
let x = obj();
let y = new Obj();
console.log(x instanceof obj); // false
console.log(y instanceof Obj); // true
Q: Which one to use?
A: Use Method 2 if you need to know its type. Useful when throwing an object (as exception) and identify its type in a try/catch context.