typeof的用法
'number': 數(shù)字
'string': 字符串
'boolean': 布爾值
'function': 函數(shù)
'object': 對象或者數(shù)組(包括null)
typeof(123) === 'number'
typeof('123') === 'string'
typeof(null) === 'object'
typeof(function() {}) === 'function'
typeof([]) === 'object'
typeof({}) === 'object'
typeof(undefined) === 'undefined'
Map的使用方法
- JavaScript的對象有個小問題,就是鍵必須是字符串。但實際上Number或者其他數(shù)據(jù)類型作為鍵也是非常合理的。為了解決這個問題,最新的ES6規(guī)范引入了新的數(shù)據(jù)類型Map。
var m = new Map([['Michael', 95], ['Bob', 75], ['Tracy', 85]]);
m.get('Michael'); // 95