As I delve into the initial concepts of Angular, I have come across a puzzling situation. Here is the code snippet:
import { Component } from '@angular/core';
@Component({
selector: 'sandbox',
template: `
<h1>Hello {{ name }}</h1>`
})
export class SanboxComponent {
name:string = "John Doe"; //name is declared as string
constructor() {
this.name = 34; //this should be the error..
}
}
Surprisingly, when I run this code on my browser, it still displays "Hello 34".
While I am familiar with JavaScript, TypeScript is relatively new to me. Based on my understanding, the designation 'name:string' implies that only a string value can be assigned. Can someone shed light on what might be happening here?