Files
Randell Dawson 1494a50123 fix(guide): restructure curriculum guide articles (#36501)
* fix: restructure certifications guide articles
* fix: added 3 dashes line before prob expl
* fix: added 3 dashes line before hints
* fix: added 3 dashes line before solutions
2019-07-24 13:29:27 +05:30

1.4 KiB

title
title
Practice comparing different values

Practice comparing different values


Hints

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


Solutions

Solution 1 (Click to Show/Hide)
// 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").

1. "Basic JavaScript: Comparison with the Strict Equality Operator", fCC lesson at JavaScript Algorithms And Data Structures Certification