Single Choice Easy

QWhat does the following function do in JavaScript?
function isPalindrome(str) {
str = str.toLowerCase();
return str === str.split('').reverse().join('');
}

ID: #4912 Javascript Functions MCQ 237 views
Question Info
#4912Q ID
EasyDifficulty
Javascript Functions MCQTopic

Choose the Best Option

Click any option to instantly check if you're correct.

  • A calculates the area of a circle
  • B converts a string to uppercase
  • C checks if a string is a palindrome
  • D sorts an array in ascending order
Correct Answer

Explanation

This function takes in a single argument, str, and uses the toLowerCase() method to convert the string to lowercase.
It then uses the split(), reverse(), and join() methods to check if the string is a palindrome (i.e., it reads the same forwards and backwards).

Share This Question

Challenge a friend or share with your study group.