The class is declared with a variable statement var Square = class {…}. The variable Square is hoisted to the top of the scope, but has an undefined value until the class declaration line. So the execution of var mySquare = new Square(10) before class declaration tries to invoke an undefined as a constructor and JavaScript throws TypeError: Square is not a constructor.

#javascript #variable #hoisting #es2015

JavaScript Variables Hoisting in Details
1.45 GEEK