Skip to content

Commit 25a8fa6

Browse files
committed
Caught a mistake I made and changed my answer
1 parent 080bc17 commit 25a8fa6

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

explicit-and-implicit-conversion-in-javascript.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ code when it produces a result of 3. No error.
2525
let result = "5" - 2;
2626
console.log("The result is: " + result);
2727

28-
/* Perhaps there is a logic error here? In that even though the boolean is false, isValid is true
29-
and so "This is valid" prints. Perhaps you should inset a not operator, !, then? Otherwise I cannot
30-
see what is wrong with this code which runs just fine.
28+
/* Although the code runs just fine, there is a logic error: when coerced to boolean a string which
29+
is not empty is true, so the string "false" actually ends up being true and so the conditionl prints
30+
this is valid. To remedy this, add the not operator, !, to the function.
3131
*/
3232
let isValid = Boolean("false");
33-
if (isValid) {
33+
if (!isValid) {
3434
console.log("This is valid!");
3535
}
3636

0 commit comments

Comments
 (0)