JavaScript AJAX Basics (retiring) Programming AJAX Parsing JSON Data

Pitrov Secondary
Pitrov Secondary
5,119 Points

What is typeof?

at 5:00 you can see that he writes typeof and it consoled "string" What is typeof?

3 Answers

Antti Lylander
Antti Lylander
9,660 Points

It's an operator that you can use to check the type of any object. String, number, function, object etc.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof

Daan Schouten
Daan Schouten
13,833 Points

Typeof literally returns the type of the variable after it. So

console.log(typeof 43);

is going to return number. It's often used in debugging or conditional statements, because it can indicate where your code is breaking or taking unexpected input.