Surya JS Journey
Learn JavaScript through concepts, code, and guided practice.
A focused workspace for concept study, interactive examples, visual explanations, and challenge solving.
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.
Editor Actions
Use the editor to explore the example, then run it to inspect the console.
Run the code to see output here.
Expected Output
true
false
falseContinue in Playground
Open this concept example in the shared playground to keep experimenting without leaving the broader workspace flow.
Open in PlaygroundRelated Concepts
Type Coercion
Type coercion is JavaScript converting one value type into another during operations or comparisons.
Truthy and Falsy
JavaScript treats some values as truthy and some as falsy when evaluating conditions.
Objects
Objects store related data and behavior as key-value pairs and are one of JavaScript’s core building blocks.