xah talk show 2019-06-07 understand JavaScript object like a mathematician

xah talk show 2019-06-07 understand JavaScript object like a mathematician
console.log ( 3 + 4 );

const obj = { a:1, b:2, "c":3, };

console.log ( obj );

// object is

// (1) foremost a collection of properties. Each property is a key and a value. So, object is a collection of key value pairs.

// The key must be of 2 datatypes: 1, string. 2 Symbol.

// the purpose of of a key that's a symbol type, is so that such properties do not easily get overwritten

// the type of a key's value, can be any js datatype

// (2), each object may have a link to another object, we call it the parent, or, the prototype object. The parent of parent etc of a object, is called the prototype chain.

// the whole point of parent or parent chain, is just when js looks up a object's key, it will try to check the parent, until a key is found, or no more parent object. This is called inheritance. And, this is the ONLY, whole, purpose, of parent, or parent chain.

console.log ( obj.a );

console.log ( typeof obj );

// creat a array. example

const ar = [3, 4, 2];

console.log ( ar );
// [ 3, 4, 2 ]

console.log ( ar.length );
// 3

ar.push ( 5 );
console.log ( ar );
// [ 3, 4, 2, 5 ]

console.log ( ar.length );
// 4

console.log ( typeof ar );
// object

console.log ( Object.keys ( ar ) );
// [ '0', '1', '2', '3' ];

// btw , to find the type of object, use the “typeof” operator

// (3) a object, may, have special behavior or internal data
// for example, js array , or function, or Map, or Set object, or date, or regex

function ff (x) { return x+1; };

console.log ( ff(5) );
// 6

// again, function is a object too. Because, you can add properties to it.

 ff.x = 3;
 ff.m = 718;

console.log (ff.x);
// 3

console.log ( Object.keys ( ff ) );
// [ 'x', 'm' ]

// JS: “typeof” Operator
// http://xahlee.info/js/js_typeof_operator.html

console.log ( typeof null );
// object

console.log ( typeof ff );
// function

console.log ( typeof ar );
// object

If you have a question, put $5 at patreon and message me.