how to declare variable in javascript class code example
Example 1: es6 class example
<script>
class Student {
constructor(rno,fname,lname){
this.rno = rno
this.fname = fname
this.lname = lname
console.log('inside constructor')
}
get fullName(){
console.log('inside getter')
return this.fname + " - "+this.lname
}
}
let s1 = new Student(101,'Sachin','Tendulkar')
console.log(s1)
console.log(s1.fullName)
</script>
Example 2: variables in js class
constructor(){
this.foo = bar
}
Example 3: how to create class in javascript
class ClassName
{
}