Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>
<div></div>
<div></div>
</body>
</html>
 
var DefaultTypes = {
    'undefined': true,
    'boolean': true,
    'number': true,
    'string': true,
    'function': true
};
function typeOf(type) {
    if (!(typeof(type) in DefaultTypes)) {
        switch (Object.prototype.toString.call(type)) {
            case '[object Array]':
                return 'array';
            case '[object Null]':
                return 'null';
            case '[object Object]':
                return 'object';
        }
    } else if (typeof(type) === 'object' && type.length) {
        return 'array-like';
    } else {
        return typeof(type);
    } 
}
console.log(typeOf(document.getElementsByTagName('div')));
console.log(document.getElementsByTagName('div').length);
console.log(typeof(document.getElementsByTagName('div')));
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
fxslokerpro
0viewers