Logical Interview Questions and Answers in JavaScript : Reverse a string

Vaibhav Sharma
2 min readMay 6, 2019

Reverse a string :

In JavaScript, you can reverse a string by three ways:

  1. Using default methods ( split (), reverse (), join ())
  2. Using decremented loop.
  3. Using of recursion function.

Using default methods:

Reverse a string by using three default or built-in functions:

  1. split () // split a string into array of character.
  2. reverse() // reverse the array.
  3. join() // join the element of the array.

Chaining all three default methods:

By using of decremented loop:

In the above function, we use the for loop for accessing the each alphabet from the last to first.

By the use of recursive method:

For reverse a string by recursive method, we can use two methods of string :

  1. substr(): The substr() method extracts parts of a string, beginning at the character at the specified position, and returns the specified number of characters.

2. charAt(): The charAt() method returns the character at the specified index in a string.

Hope you found this helpful. If you face any problem please leave a message to my email id: vsvaibhav2016@gmail.com

--

--