a = 'ghostwu'; var a; console.log( a );
console.log( a ); var a = 'ghostwu';
a = 'ghostwu'; var a; console.log( a ); //上面这段代码经过编译之后,变成下面这样 var a; //被提升到当前作用域的最前面 a = 'ghostwu'; //留在原地,等待执行 console.log( a );
console.log( a ); var a = 'ghostwu'; //上面这段代码,经过编译之后,变成下面这样 var a; console.log( a ); a = 'ghostwu';
//函数声明, 形如:
function show(){
console.log( '函数声明方式' );
}
//函数表达式, 形如:
var show = function(){
console.log( '表达式方式' );
}
show();
function show(){
console.log( a );
var a = 'ghostwu';
}
function show(){ //函数声明被提升到 当前作用域的最前面
var a; //var声明被提升到当前作用域的最前面, 注意,他不会提升到函数的外面, 因为当前的作用域是在函数中
console.log( a );
a = 'ghostwu';
}
show();
show(); //报错,show is not a function
var show = function(){
console.log( 'ghostwu' );
}
//对于上面这段表达式代码,经过编译之后:
var show;
show(); //执行之后就是 undefined(), 所以在表达式定义之前,调用函数报错了
show = function(){
console.log( 'ghostwu' );
}
show(); //你好
var show;
function show(){
console.log( '你好' );
}
show = function(){
console.log( 'hello' );
}
function show(){
console.log( '你好' );
}
show(); //你好
show = function(){
console.log( 'hello' );
}
show();//如果这里在调用一次,就是hello, 因为show函数体在执行阶段 被 重新赋值了
show(); //how are you
var show;
function show(){
console.log( 'hello' );
}
show = function(){
console.log( '你好' );
}
function show(){
console.log( 'how are you!' );
}
//上面的代码经过编译之后,变成如下形式:
function show(){
console.log( 'how are you!' );
}
show(); //how are you
show = function(){
console.log( '你好' );
}
show(); //如果在这里再执行一次,结果:你好
//思考题: 请问下面的结果是什么? 为什么? 写下你的答案
show();
var a = true;
if( a ){
function show(){
console.log( 1 );
}
}else {
function show(){
console.log( 2 );
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有