Booklet

author

Hack University

IT & Software

8 Comparison Operators In Programming

8 COMPARISON OPERATORS IN PROGRAMMING

==

𝗜𝘀 𝗲𝗾𝘂𝗮𝗹 𝘁𝗼

Compares two values (numbers, string, or booleans) to see if they 𝗮𝗿𝗲 the same.

Examples:

'Hello' == 'Goodbye' returns 𝗳𝗮𝗹𝘀𝗲 because they are 𝗻𝗼𝘁 the same string.

'Hello' == 'Hello' returns 𝘁𝗿𝘂𝗲 because they 𝗮𝗿𝗲 the same string.

!=

𝗜𝘀 𝗻𝗼𝘁 𝗲𝗾𝘂𝗮𝗹 𝘁𝗼

Compares two values (numbers, string, or booleans) to see if they are not the same.

Examples:

'Hello' != 'Goodbye' returns 𝘁𝗿𝘂𝗲 because they are 𝗻𝗼𝘁 the same string.

'Hello' != 'Hello' returns 𝗳𝗮𝗹𝘀𝗲 because they 𝗮𝗿𝗲 the same string.

===

𝗦𝘁𝗿𝗶𝗰𝘁 𝗲𝗾𝘂𝗮𝗹 𝘁𝗼

Compares two values to check that both the data type and value are the same.

Examples:

'3' === 3 returns 𝗳𝗮𝗹𝘀𝗲 because they are 𝗻𝗼𝘁 the same data type or value.

'3' === '3' returns 𝘁𝗿𝘂𝗲 because they 𝗮𝗿𝗲 the same data type and value.

!==

𝗦𝘁𝗿𝗶𝗰𝘁 𝗻𝗼𝘁 𝗲𝗾𝘂𝗮𝗹 𝘁𝗼

Compares two values to check that both the data type and value are not the same.

Examples:

'3' !== 3 returns 𝘁𝗿𝘂𝗲 because they are 𝗻𝗼𝘁 the same data type or value.

'3' !== '3' returns 𝗳𝗮𝗹𝘀𝗲 because they 𝗮𝗿𝗲 the same data type and value.

>

𝗚𝗿𝗲𝗮𝘁𝗲𝗿 𝘁𝗵𝗮𝗻

Checks if the number on the left is 𝗴𝗿𝗲𝗮𝘁𝗲𝗿 𝘁𝗵𝗮𝗻 the number on the right.

Examples:

4 > 3 returns 𝘁𝗿𝘂𝗲.

3 > 4 returns 𝗳𝗮𝗹𝘀𝗲.

<
𝗟𝗲𝘀𝘀 𝘁𝗵𝗮𝗻

Checks if the number on the left is 𝗹𝗲𝘀𝘀 𝘁𝗵𝗮𝗻 the number on the right.

Examples:

4 < 3 returns 𝗳𝗮𝗹𝘀𝗲.

3 < 4 returns 𝘁𝗿𝘂𝗲.

>=
𝗚𝗿𝗲𝗮𝘁𝗲𝗿 𝘁𝗵𝗮𝗻 𝗼𝗿 𝗲𝗾𝘂𝗮𝗹 𝘁𝗼

Checks if the number on the left is 𝗴𝗿𝗲𝗮𝘁𝗲𝗿 𝘁𝗵𝗮𝗻 𝗼𝗿 𝗲𝗾𝘂𝗮𝗹 𝘁𝗼 the number on the right.

Examples:

4 >=3 returns 𝘁𝗿𝘂𝗲.

3 >= 4 returns 𝗳𝗮𝗹𝘀𝗲.

3 >= 3 returns 𝘁𝗿𝘂𝗲.

<=
𝗟𝗲𝘀𝘀 𝘁𝗵𝗮𝗻 𝗼𝗿 𝗲𝗾𝘂𝗮𝗹 𝘁𝗼

Checks if the number on the left is 𝗹𝗲𝘀𝘀 𝘁𝗵𝗮𝗻 𝗼𝗿 𝗲𝗾𝘂𝗮𝗹 𝘁𝗼 the number on the right.

Examples:

4 <= 3 returns 𝗳𝗮𝗹𝘀𝗲.

3 <= 4 returns 𝘁𝗿𝘂𝗲.

3 <= 3 returns 𝘁𝗿𝘂𝗲.

More booklets by Hack University

More IT & Software booklets

Your recently viewed booklets

  • booklet-slide-images
  • booklet-slide-images
  • booklet-slide-images
  • booklet-slide-images
  • booklet-slide-images
  • booklet-slide-images
  • booklet-slide-images
  • booklet-slide-images
  • booklet-slide-images
  • booklet-slide-images
See all booklets