Computer >> Computer tutorials >  >> Programming >> Javascript

What are Complex Data types in JavaScript?


Complex Data Type in JavaScript includes the typeof operator. The typeof operator is a unary operator that is placed before its single operand, which can be of any type. Its value is a string indicating the data type of the operand.

The typeof operator evaluates to "number", "string", or "boolean" if its operand is a number, string, or boolean value and returns true or false based on the evaluation.

Example

You can try to run the following code to learn how to work with typeof operator in JavaScript −

<html>
   <body>
      <script>
         <!--
            var a = 10;
            var b = "String";
            var linebreak = "<br />";

            result = (typeof b == "string" ? "B is String" : "B is Numeric");
            document.write("Result => ");
            document.write(result);
            document.write(linebreak);

            result = (typeof a == "string" ? "A is String" : "A is Numeric");
            document.write("Result => ");
            document.write(result);
            document.write(linebreak);
         //-->
      </script>
   </body>
</html>