Answer: Constructor method is used for initializing object created with a class. This method is called first. If we don't specify this method, the default constructor will be used.
For example
export class App{
constructor() {
this.counter = 1;
}
}
here we are initializing teh counter property to 1 inside the constructor. Later we can use this in the view and display the value as 1 like
<template>
<p>${counter}</p>
</template>
Asked In: Many Interviews |
Alert Moderator