Why is the `typeof` operator formatted differently from other operators?

Thanks, I have a whole folder dedicated to MDN pages for fast reference.

1 Like

So an operator is “global” because it is asking about a more general property of a data type and an object attribute is more specific to a particular value?

Operators are global because they can be applied anywhere, and in some cases on any type of data. Objects contain their data and methods and either they inherit from a built in class, or they are instances of a custom class.


I think @serraphus was meaning to ask why is console.log(type newVariable); not written as console.log(newVariable.typeof());?

typeof is a global operator. It would make very little sense to have a typeof method on every class, including the ones we create.

1 Like

@malachigruenhagen834 because when you use something like blabla.something() you are calling a specific method from that specific object. since in the example newVariable is a string, you can only call methods that belong to the string object. That being said, typeof is not a method or operator of the string object, it is a global property that can be called on any data type.


The .length not an operator, it is an object property belonging to the string object.

It is a property belonging to Object.prototype that all objects inherit. Stings, arrays, and sets. These are all iterable objects so their elements can be counted.

1 Like

let newVariable = ‘Playing around with typeof.’;

console.log(typeof newVariable);

newVariable = 1;

console.log(typeof newVariable);

Why would you have to put let newVariable = 1; in this sequence instead of newVariable = 1; ?

We can only declare a variable once when let or const are used. A variable declared with let may be reassigned a value whose type need not match that of the present value.

Great explanation! I have a question that why the N in the Number is Uppercase and not the c in the console? They both are built-in objects as far as i know. Also, the M in Math. Why is it different in case of console?

1 Like

Math is a namespace object with static properties. We cannot create instances of the class, only call its methods and properties. Still, if fits the mold of a Class, so is capitalized.

Number is a constructor, so in ES6+ is a class. We can instantiate new numbers, or more commonly use the constructor to cast a number from another type, if possible, else return NaN.

a = '42'
console.log(Number(a) / 7)    //  6

console is not a class, only an object, or property of the Window class. As a property we would not capitalize it.

Please take this reply with a grain of salt and do the necessary follow up reading to either confirm, augment or refute what is written above.