Never before seen
To Quit or Not to
Go Out With a Bang
Variable annuity l
Secret and Lies an
So one thing that
Ethically Sourced
Everything Is Pers
The Sole Survivor
Being the girl tha

Baseball's greates
botingtonpost.com
This Is the Man Te
Times were tough,
Dumpster fire inte
Playing with the D
There's Gonna Be B
Always Be Moving
aislum.com
Earthquakes and Sh
I have been asked to create a simple function which takes a string, for example: "teststring" and returns the value 0, as per below: let output = "teststring" > 0; // true function stringCheck(stringToCheck) { return false; } console.log(stringCheck(output)); As you can see, this code will not produce a false value so the function should always return false. However, it always logs as true which is surprising. I expected it to always return false. What is the reason behind this? I assume it's to do with the >0, but I can't understand why it doesn't return false. A: This has to do with what operators do. Logical operators like >, != etc return true or false, the operands don't change. So even if stringToCheck would be false the function would return false. You could rewrite it like this to always get false: const stringCheck = (stringToCheck) => !stringToCheck; console.log(stringCheck('teststring')); //false console.log(stringCheck('teststring2')); //false More about logical operators in Javascript: https://developer.mozilla.org/en-US/docs/Glossary/Logical_operators#JavaScript A: Since the code output is a string, you need to convert it to a boolean. You can use a regular expression like ^\s*$ to do this, like this: let output = "teststring" const match = output.match(/^\s*$/); console.log(match); function stringCheck(stringToCheck) { return false; } console.log(stringCheck(output)); The regular expression says to look for a string of spaces (no line breaks) until it finds the end of the string (at least one space), then convert that into a boolean, which will evaluate to false. A: In Javascript, you have to be careful when working with strings and logic. Since strings are objects, the following will evaluate to true: "0" > 0; // true One way around this, as others have mentioned, is to cast it as a number using parseInt: let output = "teststring" console.log(parseInt("0") > 0); // true function stringCheck(stringToCheck) { return false; } console.log(stringCheck(output)); However, if you really need to work with strings, and you're just concerned with booleans, you can still do this by using RegExp: let output = "teststring" console.log(/teststring/i.test(output)); // true console.log(/teststring/.test(output)); // false This will return a boolean value, the string can be any value, it's just a condition that must be true. So, if output = "False", it will return true. This does answer your original question, however I wanted to point out some other mistakes in the example: "teststring" > 0; // true "teststring2" > 0; // true The first one will evaluate to true since the strings are not equal. Just keep that in mind. And also, the logic of the string compare is wrong. > should be used to compare strings for a case-insensitive search. It doesn't evaluate booleans. let output = "teststring" console.log(output > "teststring2"); // false And you should really read this, it's a great explanation of strings in javascript.