What does the term "Type operator" mean?

A type of operator which tells you how a particular piece of code or variable is stored in your program.

Type operators are not available in all programming languages.

Although they vary in how they are written between languages, the type operators are roughly as follows:

OperatorExampleDescription
typeoftypeof “John” returns “string”
typeof 3.14 returns “number”
Tells you what data type your variable is using.

It returns this information in the form of a operand with a data type of string.

This can be useful for telling you if you have stored a number in a variable in a way that you can perform maths upon it (an integer) or not (a string).

Sometimes the result is not useful for providing specifics e.g. in Javascript you can use a type operator on a date or array, but these would return object.

instanceofinstanceof jack-russel-terrier returns true (of the class dog)Tells you if your object is an instance of something and returns true if it is, and false if it is not.

Leave a Reply

Thank you for choosing to leave a comment. Comments may be moderated.