How to check whether a passed string is palindrome or not in JavaScript ?

How to check whether a passed string is palindrome or not in JavaScript ?Given a string, our task is to find string is palindrome or not.Example:
Input : “race”
Output : passed string is not a palidrome
Explanation : if we write “race” in reverse that is “ecer” it not
matches with first string so it is not a pallindrome.
Example 2:
Input : “hellolleh”
Output : passed string is palidrome.Approach 1: In this approach we use following steps.First we iterate over a string in forward and backward direction.Check if all forward and backward character matches, return true.If all forward and backward character does not matches, return false.If return is true, it is a palindrome.Example:Javascript    function check_palindrome( str )  {    let j = str.length -1;    for( let i = 0 ; i < j/2 ;i++)    {      let x = str[i] ;      let y = str[j-i];      if( x != y)      {                return false;      }    }        return true;        }      function is_palidrome( str )  {        let ans = check_palindrome(str);        if( ans == true )    {      console.log("passed string is palindrome ");    }    else    {      console.log("passed string not a palindrome");    }  }    let test = "racecar";  is_palidrome(test);Output :passed string is palidrome.Approach 2: Another approach is to reverse a string and check if the initial string matches with the reverse string or not.Follow the following steps :Initialize revese_str a variable which stores reverse of the passed string.Compare the string to reverse_str .If matches, it is a palindrome.Else string is not a palindrome.Example:Javascript    function reverse( str )  {        let rev_str = "";    for( let i = str.length-1 ;i >= 0 ;i–)    {      rev_str+= str[i];    }        return rev_str;  }      function is_palindrome( str )  {    reverse_str = reverse(str);                if( reverse_str === str)    {      console.log(“passed string is palindrome “);    }    else    {      console.log(“passed string is not palindrome”)    }  }  let test = “hellolleh”;  is_palindrome(test);Output :passed string is palidrome.