<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
</body>
</html>
<script>
// 函数提升:
// 函数声明的方式声明函数,整个函数会提升
// 函数表达式的方式声明函数,只有 var func2; 会提升,func2 = function(){}不会提升
console.log(func1()); // 1
console.log(func2()); // Uncaught TypeError: func2 is not a function
// 函数声明
function func1() {
return 1;
}
// 函数表达式
var func2 = function () {
return 2;
}
</script>
6、js - 面试 - 函数提升
于 2023-05-24 10:15:00 首次发布