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
已聲明的對象不可刪除, 對象中的對象屬性能夠刪除對象