For your example, when the code transpiled to JS - there is no difference (see @Gil's answer).
In TypeScript actually there is a difference (but not in your example, since your constructor does not have any arguments).
If you want to pass arguments to the constructor class - then the magic of TypeScript happens because TS includes a concise way to create and assign a class instance property from a constructor parameter.
Let's say we have a class:
class MyClass {
private prop: string;
constructor(prop: string) {
this.prop = prop;
}
}
You can write it in ONE line of code adding property modificators:
class MyClass {
constructor(private prop: string) { }
}
This will create prop
property in the class and also initialize it with new value from constructor argument. Define private/public/protected
modificators is up to you (it depends on your class's logic).
Last case - if you don't set modificator:
class MyClass {
constructor(prop: string) {
// prop variable is available here
}
// prop variable is not available outside the constructor method
}