显式声明变量和隐式声明变量的区别

区别1:在函数中,显式声明变量式局部变量,隐式变量 式全局变量;
区别2:隐式声明的变量可以被删除,显式变量不能删除;
区别3:隐式声明变量的默认配置configurble为true,显式声明变量的默认配置configurable为false;

var abc = 123;// 显式声明变量
str = 'abc';// 隐式声明变量

console.log( window.abc );// 123
console.log( window.str );// 'abc'

delete window.abc;
delete window.str;

console.log( window.abc );// 123
console.log( window.str );// undefined

var abcDesc = Object.getOwnPropertyDescriptor(window,'abc');
var strDesc = Object.getOwnPropertyDescriptor(window,'str');
console.log( abcDesc );
console.log( strDesc );

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值