变量提升(Hoisting)
-
- 什么类型有变量提升
- 函数类型
- var 声明的变量类型
-
- 变量提升的用处
- 将代码提升到底部使用
代码
import xxx from "././project";
import xxx from "././project";
import xxx from "././project";
const storageState = useStorage(),
mainState = useStorage();
let num1 = ref(0),
num2 = ref(0),
num3 = ref(0);
const msg = ref([]),
msg2 = ref({}),
msg3 = ref({});
const formData = reactice({}),
msgData = reactice({});
const sum = (a, b) => {},
msg = () => {},
handleLogin = () => {},
multiply = (a, b) => a * b;
const sum1 = () => {},
msg = () => {},
handleLogin = () => {};
sum(6, 2);
msg();
handleLogin();
sum();
function sum() {
console.log(num1 + num2);
}
var num1 = 10,
num2 = 5;
总结
- 真正的魔法发生在执行上下文的创建阶段
- 我相信要有好的代码结构,应该在顶部建立
变量
- 在调用函数之前应该始终先建立函数 => 这才是良好的代码结构