// Function to reverse a string
function reverseString(str) {
return str.split('').reverse().join('');
}
// Example usage
const originalString = "Hello, World!";
const reversedString = reverseString(originalString);
console.log(reversedString); // Output: '!dlroW ,olleH'
In the example above, we take the string "Hello, World!"
and pass it to the reverseString
function. The output, as shown in the console, is "!dlroW ,olleH"
.