JS Startup

Challenges, Tips & Tricks & Tutorials

JavaScript Quiz – Find out the output of a reverse string

JavaScript Quiz – Find out the output of a reverse string

Reverse String –

A reverse string is a concept for reverse a string and converts to a new string. There is no built-in method in String, which can achieve this concept.

We need to convert a string to an array and then reverse it. At last, we join that array and make a string.

Another way of doing it. you can use a loop to reverse a string. As you can also access string like an array using an index.

Question –

In this javascript quiz, you need to find out the output of string which is reversed.

So, here we declare a variable string using let keyword and assign “racecar” to it.

Then, we use 3 array method to achieve a reverse split(), reverse() & join().

First, we convert a string to an array using the split() method. Then reverse it using the reverse() method and now convert array to string using join() method.

Now, we `console.log(string);` to find out, what is the output? or Does it really working? Who knows, you need to figure it out.

Answer – “racecar”

Click To Run code

Explanation –

First, we declare variable string.

let string = “racecar”;

Here, we use a string split() method because with the help of it. We are able to convert string to an array.

The string does not have a reverse() method but array had a reverse() method to reverse an array element.

So, we use reverse() array method to reverse an array element. Now, after it. we use the join() array method to convert it back to a string.

string = [ “r”, “a”, “c”, “e”, “c”, “a”, “r” ];

string = “racecar”

Point To Note: “racecar” still gives “racecar“. As the reversed version is the same as the original string.

Check out our other javascript quiz – 



To participate in our javascript quiz or challenges, tutorial, tips & tricks make sure to join our jsstartup newsletter. So, you can able to participate in our daily challenges & learn the javascript concept.

And last but not the least, don’t forget to like, comment and share. It gives us a morale boost to remain to continue. Also, join our Facebook Page

If you have any questions, please feel free to ask me in the comment section and also let me know if you have any suggestions. As suggestions are always welcome.

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top
1 Share
Share via
Copy link