I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.
You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.
You’ve just called the function detail normally, so it doesn’t return anything, so there is no property called name because you haven’t created an object.
var person = detail("Max", 31, "Programmer");
person has the value undefined assigned to it, undefined.name is not a thing.
var person = new detail("Max", 31, "Programmer");
person has the object { name: "Max", age: 31, work: "Programmer" } assigned to it
Couple of things:
constructor functions should be capitalised (Detail not detail). This doesn’t make any difference to functionality: it’s just convention. But it makes it obvious that it’s a function that is to be used as a constructor.
using class eliminates the issue, because it won’t let you call the constructor without new: