1//checks if is object, null val returns false
2function isObject(val) {
3 if (val === null) { return false;}
4 return ( (typeof val === 'function') || (typeof val === 'object') );
5}
6var person = {"name":"Boby Snark"};
7isObject(person);//true
1var person = {
2 first_name : "Marty",
3 last_name : "Mcfly",
4 born : 1968,
5 died : 1933,
6 lovers: ["Jennifer Parker","Baines McFly"]
7};
1let object = {
2 'key1': 'value1',
3 'key2': 'value2',
4 'keyn': 'valuen',
5};
6console.log(object);
1let car = {
2 name: "BMW",
3 colour: "black",
4 year: "2020",
5 owner: {
6 names = ["Andy" , "Steve" , "Tony" ]
7 }
8};
1person = {
2 'name':'john smith'
3 'age':41
4};
5
6console.log(person);
7//this will return [object Object]
8//use
9console.log(JSON.stringify(person));
10//instead
1'use strict';
2
3var obj = {
4 a: 10
5 b:20
6};
7
8Object.defineProperty(obj, 'b', {
9 get: () => {
10 console.log(this.a, typeof this.a, this); // undefined 'undefined' Window {...} (or the global object)
11 return this.a + 10; // represents global object 'Window', therefore 'this.a' returns 'undefined'
12 }
13});
14