Reputation: 11756
This is a very simple question, so I'll be brief. Is there any difference in these two code snippets?
class Test {
constructor(value?: number = 5) { }
}
class Test {
constructor(value: number = 5) { }
}
My assumption is that there is none, because including the default initialized value implicitly makes it also an optional parameter. If that is indeed the case, is it better to include the question mark, or not?
Upvotes: 2
Views: 682
Reputation: 187034
Your first snippet is actually a type error.
Parameter cannot have question mark and initializer.(1015)
So I think that should settle it.
Upvotes: 3