I am new to js
, trying to learn js
, can you guys tell me why typeof typeof x
returns string
, providing code snippet below, if i understand this simple concept it will help me more:
var x=null;
console.log(typeof typeof x);
I am new to js
, trying to learn js
, can you guys tell me why typeof typeof x
returns string
, providing code snippet below, if i understand this simple concept it will help me more:
var x=null;
console.log(typeof typeof x);
typeof operator to find the data type of a JavaScript variable // This stands since the beginning of JavaScript typeof null === 'object';
typeof x
returns a string representation of the type ofx
. So, naturally,typeof typeof x
is string.From MDN:
Check this simple example, it will clear your doubt:
Reason:
typeof
returns a string, of the type of the value you provided, When you check the value returned bytypeof
, it will be in string form, like:And you are checking the
typeof "object"
, that's why it returnedstring
.