Surya JS Journey

Learn JavaScript through concepts, code, and guided practice.

A focused workspace for concept study, interactive examples, visual explanations, and challenge solving.

Core JavaScriptBeginner

Equality

JavaScript has loose and strict equality, and they behave differently because loose equality allows coercion.

Strict equality (`===`) compares both value and type, while loose equality (`==`) may convert values before comparing them. Most JavaScript code should prefer strict equality because it avoids surprising conversions and makes conditions easier to reason about.

Explanation

Strict equality (`===`) compares both value and type, while loose equality (`==`) may convert values before comparing them. Most JavaScript code should prefer strict equality because it avoids surprising conversions and makes conditions easier to reason about.

Key Points

  • `===` compares without coercion.
  • `==` may coerce values before comparing them.
  • Reference types compare by reference, not by content.

Common Mistakes

  • Using `==` because it appears shorter, not because coercion is intentionally needed.
  • Expecting two identical object literals to be equal with `===`.
  • Mixing equality rules in the same codebase and making conditionals harder to read.

Practice Workspace

equality.js

Edit the code, run it in the browser, and inspect the console output below. Reset restores the original snippet for this page.

Editor

3 lines

Output

0 entries

Mode

practice

Workspace Notes

Changes stay local until you run the code. Reset restores the original snippet immediately for another pass.

Live editing

Safe to change before every run.

Fast reset

Return to the original starter instantly.

equality.js
3 linesMonaco Editor
Loading...

Editor Actions

Use the editor to explore the example, then run it to inspect the console.

Console0 entries

Run the code to see output here.

Expected Output

true
false
false

Continue in Playground

Open this concept example in the shared playground to keep experimenting without leaving the broader workspace flow.

Open in Playground