代码示例:(标识:js_classes_hoisting)
<!DOCTYPE html>
<html>
<body>

<h1>JavaScript 类没有被提升</h1>

<p>如果在声明类之前尝试使用类,则会出现错误。</p>

<p id="demo"></p>

<script>
//You cannot use the class yet.
//myCar = new Car("Ford")
//This would raise an error.

class Car {
  constructor(brand) {
    this.carname = brand;
  }
}

//Now you can use the class:
let myCar = new Car("Ford")
</script>

</body>
</html>
运行结果: