Skip to content

Javascript escape single quote function parameter | Example code

  • by

Use ‘escape sequence’. Place a backslash \ before a single quote to escape a single quote function parameter in JavaScript.

    alert('EyeHunt\'s Answer');

Without backslash it will throw error:

Uncaught SyntaxError: missing ) after argument list

Passing a parameter to function with a single quote example

HTML example code, escape quotes/characters by prepending \ to it. A simple function to demonstrate how to work with string quotes in function and show output in console log.

<!DOCTYPE html>

    var str1 = 'my string with "double quotes" and \'single quotes\'';
    var str2 = "my string with 'single quotes' and \"double quotes\"";

    function show(str) {


Javascript escape single quote function parameter

Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.

OS: Windows 10

Code: HTML 5 Version

Leave a Reply

Discover more from Tutorial

Subscribe now to keep reading and get access to the full archive.

Continue reading