javascript / beginner
Snippet
Strict Equality for Comparisons
Using the strict equality operator (===) ensures that both the value and the data type are exactly the same, preventing unexpected bugs in logic.
snippet.js
1
2
3
4
5
const RoleCheck = (props) => {const isAdmin = props.role === "admin";return <p>{isAdmin && "Admin Access Granted"}</p>;};
react
Breakdown
1
props.role === "admin"
Checks if the role is the string 'admin' in both value and type.