Logo

Programming-Idioms

History of Idiom 94 > diff from v36 to v37

Edit summary for version 37 by programming-idioms.org:
New JS implementation by user [programming-idioms.org]

Version 36

2019-01-23, 19:25:57

Version 37

2019-09-01, 12:42:08

Idiom #94 Print type of variable

Print the name of the type of x. Explain if it is a static type or dynamic type.

This may not make sense in all languages.

Idiom #94 Print type of variable

Print the name of the type of x. Explain if it is a static type or dynamic type.

This may not make sense in all languages.

Code
console.log (x == null ? x + '' : x.constructor.name);
Comments bubble
Gives you the name of the function used to build x—it always works due to the "everything is an object" principle.