Learn
Variables
typeof operator
The typeof
operator is used to determine the type of a value or variable. It returns a string indicating the type of the operand.
Syntax
The syntax of the typeof
operator is as follows:
Usage
The typeof
operator can be used with different types of operands.
Here are some examples:
- Checking the type of a variable:
- Checking the type of a numeric value:
- Checking the type of a boolean expression:
- Checking the type of an undefined value:
The typeof
operator is a useful tool in JavaScript for determining the type of a value or variable. It returns a string representing the data type of the operand.
Understanding the type of data can help in writing more robust and error-free code.
Instructions
1.
Declare a variable named result1
and assign it the result of applying the typeof
operator to the variable num
.
2.
Print the value of the result1
variable to the console.
Sign up to start coding
Already have an account?
Sign In
Course content