Posts

freeGlobal

Returns the nodejs global object if exists.

createMathOperation

If both arguments are undefined then the default value passed in is returned. If one of the argument is the undefined, then the other is returned. If one of the arguments is string then the other argument is also converted to string and run thru the operation function passed in. Any other type, the arguments are converted to a number and the operation is tried. If not a number then NaN would be used.

baseToString

Before we go for conversion, we can first try typeof value. If it returns string then we don't have to do any conversion. If the value is array then we need to convert each of its value to its string form. if (Array.isArray(value)) { return `${value.map(baseToString)}` } If it is a symbol then we need to convert it to symbol's toString. console.log(Symbol.prototype.toString.call(Symbol.toStringTag)) Output: Symbol(Symbol.toStringTag) Anything else we just need to parse. const value = true console.log(`${value}`) Output: true

baseToNumber

If the value is string, it can be converted to its numeric form using + . console.log(typeof "1") console.log(typeof +"1") If the value is symbol , NaN will be returned. Output: string number

isSymbol

This determines if an object is of type Symbol . Easiest way is to simply use typeof . If its value is 'object', we can then look into its > toString value . console.log(typeof Symbol.toStringTag) console.log(Object.prototype.toString.call(Symbol.toStringTag)) Output: symbol [object Symbol]

getTag

getTag returns string representation of Object.We may not expect the right value for data views, maps, sets, and weak maps in IE 11 and promises in Node.js < 6 We expect DataView - [object DataView] Map - [object Map] Promise - [object Promise] Set - [object Set] WeakMap - [object WeakMap] In all the above cases where we don't get the value as expected, we derive at the object's type using its constructor. console.log(`${DataView}`) const o = new DataView(new ArrayBuffer(1)) console.log("Based on o.constructor") console.log(`${o.constructor}`) Output: function DataView() { [native code] } Based on o.constructor function DataView() { [native code] }