Chinese input methods, understand JavaScript object in depth, in a math style. Xah Talk Show 2019-09-13

Chinese input methods, understand JavaScript object in depth, in a math style. Xah Talk Show 2019-09-13

topics covered:

First of all, understand JavaScript value types.

console.log ( undefined );
console.log ( typeof undefined === "undefined" );
console.log ( true );
console.log ( typeof true === "boolean" );
console.log ( typeof NaN === "number");
console.log ( typeof Infinity === "number" );
console.log ( typeof 3 === "number" );
console.log ( typeof 3.12345 === "number" );

finding the type of a value

function ff (x) { return x+1 }
console.log ( typeof ff === "function" );

what is object in JavaScript?

JavaScript object is:

function ff () { return 3 };

console.log ( ff() );

ff.aa = 4;
ff.bb = 5;

console.log ( ff );
const aa = [3,4,5];

console.log ( typeof aa );

console.log ( Array.isArray(aa) );

console.log ( Reflect.ownKeys ( aa ) );

// this is what array is like as a property
// {"0":3, "1":4, "2":5 ,  "length":someInternalMagicFunction}
const obj = {k1 : 1, k2 : 2};
console.log ( obj );
console.log ( Reflect.ownKeys (obj) );
// this is about inheritance. when js looks up a property's value, it tries to go up the parent chain

const x1 = {k3 : 3};

const x2 = {k1 : 1, k2 : 2};

Reflect.setPrototypeOf ( x2, x1 );

console.log ( x2.k3 );

// this is about inheritance. when js looks up a property's value, it tries to go up the parent chain

const x1 = {k3 : 3};

const x2 = {k1 : 1, k2 : 2};

Reflect.setPrototypeOf ( x2, x1 );

console.log ( x2.k3 );

x1.k3 = 4;

console.log ( x2.k3 );

x2.k3 = 5;

console.log ( x2.k3 );

console.log ( Reflect.ownKeys ( x2 ) );

xah_talk_show_2019-09-13.txt

xah talk show 2019-09-13 836x9
xah talk show 2019-09-13 836x9

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