I was writing a simple if condition that checks the type of the input. I used !typeof str == "string"
it did not work, so i used typeof str != "string"
instead of it. it worked. this is the function:
function reverseStr(str) {
if (typeof str != "string" || !str) {
return "Please enter a valid str";
}
var oldList = str.split("");
var newList = [];
for (let i = oldList.length - 1; i >= 0; i--) {
newList.push(oldList[i]);
}
return newList.join("");
}
so what is the difference between them?