Tell us what’s happening:
Hi I passed the test but I wonder how do the computer knows that 12 is equal to val when its not a number?
Your code so far
// Setup
function testEqual(val) {
if (val == 12) { // Change this line
return "Equal";
}
return "Not Equal";
}
// Change this value to test
testEqual(10);
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/comparison-with-the-equality-operator
Of course val is a number. val represents the number passed into the function.
In the example call of the function below, the number 10 is passed into the function, so val is 10. Since 10 == 12 evaluates to false, the if statement block of code is not executed and the next line (return “Not Equal”
gets executed instead.
testEqual(10);
In the example call of the function below, the number 12 is passed into the function, so val is 12. Since 12 == 12 evaluates to true, the if statement block of code is executed, so the line (return “Equal”) gets executed.
testEqual(12);
In the compiler it searchers back up to the last time the variable was changed and comes back and uses that.