What is the difference between a constructor function that creates an object like this:
function User(name) {
this.name = name;
this.isAdmin = false;
}
let user = new User("Jack");
and a non constructor function that looks like this:
function user(name, age) {
return {
name,
age,
}
};
let user = user("Tom", 23);
I am currently learning about constructor functions and it does not make sense for me to use them if you can replace them with the function above. Can anybody explain how a constructor function is more useful in practise?