1.5 KiB
1.5 KiB
title |
---|
Practice comparing different values |
Practice comparing different values
Problem explanation:
· Modify the function so that it returns "Equal" only when the values are strictly equal.
Hint 1
Remember from last exercises that unlike the equality operator, which attempts to convert both values being compared to a common type, the strict equality operator does not perform a type conversion.1
try to solve the problem now
Spoiler alert!
Solution ahead!
Basic code solution:
// Setup
function compareEquality(a, b) {
if (a === b) { // Change this line
return "Equal";
}
return "Not Equal";
}
// Change this value to test
compareEquality(10, "10");
Code explanation
The function first evaluates if
the condition (a === b)
evaluates to true
considering both type and value. If it does, it returns the statement between the curly braces ("Equal"). If it doesn't, it returns the next return
statement outside them ("Not equal").