What is the difference between new ObjectId() and new ObjectId and ObjectId()?

Viewed 3623

Suppose that I have this definition at the beginning of a file:

const ObjectId = mongoose.Types.ObjectId;

Which one should you prefer and why?

// 1 
new ObjectId;  

// 2
new ObjectId();

// 3
ObjectId();

The official document suggests using new ObjectId. For me new ObjectId() feels more natural but each of them generates a new ObjectId and I have seen examples for each of them in SO's questions and answers.

http://mongoosejs.com/docs/api.html#types-objectid-js

Update: Let me clear this: I know why and how to use a new operator in JavaScript, I just want to find out is there any significant difference when new is used for ObjectID generation. (The function behaves different, throws an error, etc ...)

1 Answers
Related