typeof Operator

The JavaScript typeof operator returns the data type of its operand in the form of a string. The operand can be any object, function, or variable.

Syntax:

typeof operand

Example: In this example, The typeof operator is used to check the data types of variables. Outputs: “number”, “string”, “boolean”, “object”, and “undefined” for each respective variable.

Javascript




let num = 18;
let str = "w3wiki";
let isTrue = true;
let obj = { name: "Aman", age: 21 };
let undefinedVar;
  
console.log(typeof num);
console.log(typeof str);
console.log(typeof isTrue);
console.log(typeof obj);
console.log(typeof undefinedVar);


Output

number
string
boolean
object
undefined

JavaScript Unary Operators

JavaScript Unary Operators work on a single operand and perform various operations, like incrementing/decrementing, evaluating data type, negation of a value, etc.

Table of Content

  • Unary Plus (+) Operator
  • Unary Minus (-) Operator
  • Unary Increment (++) Operator
  • Unary Decrement (–) Operator
  • Logical NOT (!) Operator
  • Bitwise NOT (~) Operator
  • typeof Operator
  • delete Operator
  • void Operator

We will explore all the above operators along with their basic implementation with the help of examples.

Similar Reads

Unary Plus (+) Operator

The unary plus (+) converts an operand into a number, if possible. It is commonly used to ensure numerical operations on variables that may contain numeric strings. If the operand is a string that represents a valid number, it will be converted to a number. Otherwise, it will evaluate to NaN (Not-a-Number)....

Unary Minus (-) Operator

...

Unary Increment (++) Operator

The Unary Negation (-) operator is used to convert its operand to a negative number if it isn’t already a negative number....

Unary Decrement (–) Operator

...

Logical NOT (!) Operator

The unary increment operator (++) adds 1 to its operand’s value and evaluates to the updated value. It can be used as a postfix or prefix operator....

Bitwise NOT (~) Operator

...

typeof Operator

The unary decrement operator (–) subtracts 1 from its operand’s value and evaluates it to the updated value, and we can use it as a postfix or prefix operator....

delete Operator

...

void Operator

The logical NOT (!) is a unary operator that negates the Boolean value of an operand, converting true to false and false to true....