JavaScript Tutorial

jQuery.isPlainObject()

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
    // Also see https://github.com/lodash/lodash/blob/master/dist/lodash.js#L10148
    function isPlainObject(o) {
        // return typeof o === 'object'; // fails
        // return o === Object(o); // fails
        // return o instanceof Object; // fails
        return !!o 
        && typeof o === 'object'
        && Object.prototype.toString.call(o) === '[object Object]';
    }
    // examples
    function Foo() { this.a = 1; }
    console.log('Math => false', isPlainObject(Math));
    console.log('Math.abs => false', isPlainObject(Math.abs));
    console.log('class => true', isPlainObject(new Foo));
    console.log('array => false', isPlainObject([1, 2, 3]));
    console.log('{} => true', isPlainObject({ 'x': 0, 'y': 0 }));
    console.log('Object.create(null) => true', isPlainObject(Object.create(null)));
    console.log('Object.prototype => true', isPlainObject(Object.prototype));
    console.log('Object => false', isPlainObject(Object));
    console.log('null => false', isPlainObject(null));
    console.log('"str" => false', isPlainObject('str'));
    console.log('5 => false', isPlainObject(5));
    console.log('true => false', isPlainObject(true));
    console.log('undefined => false', isPlainObject(undefined));
    console.log('new Date() => false', isPlainObject(new Date()));
</script>
</head>
<body>
<p id="p1">Please Check console.</p>
</body>
</html>