Function 1 and Function 2 both are the same but with a different syntax. The thing is that when I call function 2 (arrow function syntax) in isItAPalindrome function it gives me a "is not defined" error. But when I declared function 2 within isItAPalindrome function it does not give me any error.
Function 1:
function reverseStr(str){
return str.toLowerCase().split('').reverse().join('');
}
Function 2:
const reverseStr = (str) => str.toLowerCase().split('').reverse().join('');
When I call the function 1 it works the way it's supposed to do.
function isItAPalindrome(str) {
//When I call the arrow function here it works.
//const reverseStr = (str) => str.toLowerCase().split('').reverse().join('');
if (str.toLowerCase() == reverseStr(str)) {
return "It's a palindrome!";
} else {
return "It's not a palindrome!";
}
}
console.log(isItAPalindrome("sum mus"));
Why does this happen with the arrow functions in?