var obj={ name: 'zhagnsan', age: 19 } delete obj.name //true typeof obj.name //undefined
1.变量数组
var name ='zs' //已声明的变量 delete name //false console.log(typeof name) //String age = 19 //未声明的变量 delete age //true typeof age //undefined this.val = 'fds' //window下的变量 delete this.val //true console.log(typeof this.val) //undefined
已声明的变量不可删除, 未声明的变量能够删除函数
2.函数this
var fn = function(){} //已声明的函数 delete fn //false console.log(typeof fn) //function fn = function(){} //未声明的函数 delete fn //true console.log(typeof fn) //undefined
3.数组spa
var arr = ['1','2','3'] ///已声明的数组 delete arr //false console.log(typeof arr) //object arr = ['1','2','3'] //未声明的数组 delete arr //true console.log(typeof arr) //undefined var arr = ['1','2','3'] //已声明的数组 delete arr[1] //true console.log(arr) //['1','empty','3']
4.对象code
var person = { height: 180, long: 180, weight: 180, hobby: { ball: 'good', music: 'nice' } } delete person ///false console.log(typeof person) //object var person = { height: 180, long: 180, weight: 180, hobby: { ball: 'good', music: 'nice' } } delete person.hobby ///true console.log(typeof person.hobby) //undefined
已声明的对象不可删除, 对象中的对象属性能够删除对象