In following component class, if I add let keyword, the code doesn't compile. Why?
export class HelloComponent {
@Input() name: string;
name2:string;//let name2:string doesn't compile.
constructor(){
}
}
let and var are only required/allowed for local variables, not for class fields.
export class HelloComponent {
@Input() name: string;
name2:string;//let name2:string doesn't compile.
constructor(){
var x = 5; // ok
let y = 5; // ok
const z = 5; // ok
}
}
In a class outside a method (or constructor) only variable initialization and method declaration is allowed, therefore let is redundant and therefore not allowed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With