Golang Tutorials - Learn Go Programming with Easy Step-by-Step Guides

Explore comprehensive Golang tutorials for beginners and advanced programmers. Learn Go programming with easy-to-follow, step-by-step guides, examples, and practical tips to master Go language quickly.

Js Comments in JavaScript

Js Comments in JavaScript

?? JavaScript Comparisons


Types of Comparison Operators

1. Equality

OperatorDescriptionExampleResult
==Loose equality (value only)5 == '5'true
===Strict equality (value and type)5 === '5'false

2. Inequality

OperatorDescriptionExampleResult
!=Loose inequality (value only)5 != '6'true
!==Strict inequality (value or type)5 !== '5'true

3. Relational Operators

OperatorDescriptionExampleResult
<Less than3 < 5true
>Greater than7 > 10false
<=Less than or equal5 <= 5true
>=Greater than or equal6 >= 4true

Important Notes

  • Use strict equality (===) to avoid unexpected type coercion.

  • == converts operands to the same type before comparison — this can lead to surprises:

console.log(0 == false);  // trueconsole.log(0 === false); // false

Comparing Objects and Arrays

  • Objects and arrays are compared by reference, not by value.

const a = [1, 2];const b = [1, 2];console.log(a == b);  // falseconsole.log(a === b); // falseconst c = a;console.log(a === c); // true

Special Cases

  • NaN is not equal to anything, including itself:

console.log(NaN == NaN);  // falseconsole.log(NaN === NaN); // false
  • Use Number.isNaN() to check for NaN.


Want me to explain type coercion rules or give examples of common pitfalls with comparisons?

Disclaimer for AI-Generated Content:
The content provided in these tutorials is generated using artificial intelligence and is intended for educational purposes only.
html
docker
php
kubernetes
golang
mysql
postgresql
mariaDB
sql