JAVASCRIPT Tutorial

Relational Operators

Relational operators are used to compare two values and return a boolean (true or false) value. They help you determine the relationship between two values.

Types of Relational Operators

Operator Description
== Checks for equality (value comparison)
!= Checks for inequality (value comparison)
< Checks if the left operand is less than the right operand (value comparison)
> Checks if the left operand is greater than the right operand (value comparison)
<= Checks if the left operand is less than or equal to the right operand (value comparison)
>= Checks if the left operand is greater than or equal to the right operand (value comparison)

Key Concepts

  • Type Checking: Verifying whether a value belongs to a specific type.
  • Property Check: Examining whether an object has a specific property.
  • Value Comparison: Evaluating whether the values of two operands are equal or different.
Operators Used to Check Properties or Types of Values (typeof and instanceof)
  • typeof: Returns the type of a value (e.g., "string", "number").
  • instanceof: Checks if an object belongs to a specific class or constructor.

JavaScript Example

// Value Comparison
console.log(10 == 10); // true
console.log(10 != 10); // false

// Type Checking and Property Check
console.log(typeof "Hello"); // string
console.log("Hello" instanceof String); // true