💾typeName()
JS ⟩ value ⟩ type ⟩ name ⟩ typeName()
printPrototypeChain() - print the prototype chain of an object.
replit:typeName() (v.2)
typeof base type expr value
--------------------------------------------------------------------------
object⭐️ Null Null null null
--------------------------------------------------------------------------
undefined Undefined Undefined undefined undefined
--------------------------------------------------------------------------
number Number Number 37 37
number Number Number 3.14 3.14
number Number Number Math.LN2 0.6931471805599453
number Number Number Infinity Infinity
number Number Number NaN NaN
number Number Number Number('1') 1
number Number Number Number('ab') NaN
--------------------------------------------------------------------------
bigint BigInt BigInt 42 42n
--------------------------------------------------------------------------
string String String 'bla' bla
string String String `x = ${1+2}` x = 3
string String String typeof 1 number
string String String String({}) [object Object]
string String String typeof xxx undefined
--------------------------------------------------------------------------
boolean Boolean Boolean true true
boolean Boolean Boolean Boolean(1) true
boolean Boolean Boolean !!(1) true
--------------------------------------------------------------------------
symbol Symbol Symbol Symbol() Symbol()
symbol Symbol Symbol Symbol.iterator Symbol(Symbol.iterator)
--------------------------------------------------------------------------
object Object Object {a:1} { a: 1 }
object⭐️ User User user User { name: 'JohnDoe' }
object⭐️ Array Array [1, 2] [ 1, 2 ]
object⭐️ Date Date new Date() 2022-09-13T01:26:32.214Z
object⭐️ RegExp RegExp /regex/ /regex/
--------------------------------------------------------------------------
function Function Function function(){} [Function (anonymous)]
function Function Function Math.sin [Function: sin]
function Function Function () => {} [Function (anonymous)]
function⭐️❗ Function class class {} [class (anonymous)]
function⭐️❗ Function class User [class User]
function⭐️ GeneratorFunction GeneratorFunction function*(){} [GeneratorFunction (anonymous)]
--------------------------------------------------------------------------
• ⭐️ types not all the same • ❗ base !== typereplit:typeName() (v.2)
require: isClass(), baseTypeName()
📁 module (copy and paste this file to use it)
replit:typeName() (v.2)
📁 index.js
📁 testCases.js
objects can change the behavior of Object.prototype.toString() by defining a Symbol.toStringTag property, leading to unexpected results:
Last updated
Was this helpful?