0

In the following class which makes use of the new instance field syntax:

class Range2 {
    default = 77;
    constructor(from, to) {
        this.from = from;
        this.to = to;
    }

Does this get end up acting the same as:

class Range2 {
    constructor(from, to) {
        this.from = from;
        this.to = to;
        default = 77;
    }

And do all variables outside a function get hoisted to the top of the class, or how does that work?

David542
  • 104,438
  • 178
  • 489
  • 842
  • What happened when you tried it? Was `Range2(1,2).default` equal to 77? – kindall Oct 20 '21 at 00:06
  • It's not a variable, it's a property. And its initialisation happens at the top of the constructor not at the bottom. – Bergi Oct 20 '21 at 01:31

0 Answers0