In programming, it is often necessary to check the type of a variable to ensure that it contains the expected value.In JavaScript, the `typeof` operator can be used to check the type of a variable.For example, the following code checks if the variable `x` is a number:
if (typeof x === 'number') {// The variable `x` is a number}The `typeof` operator can also be used to check the type of an object.For example, the following code checks if the variable `obj` is an array: