ES6: Use class Syntax to Define a Constructor Function - question on function

For this exercise doesnt make sense why you would nest a class inside a function, im able to output the same result just with a class

class Vegetable {
constructor(name){
this.name = name;
}
}

const carrot = new Vegetable(‘carrot’);
console.log(carrot.name); // => should be ‘carrot’

It is indeed unusual to nest a class inside a function, at least a non-IIFE function. I’m not sure why the challenge is written that way – it may have something to do with the tests needing a fresh definition of the class for each test.