LaVOZs

The World’s Largest Online Community for Developers

'; node.js - Using Javascript and EJS why might the \ escape character turn one quote " into two quotes ""? - LavOzs.Com

Environment: Node.js, Express, EJS

Question: Why might the \ escape character turn one quote " into two quotes ""?

Background: In the following simplified example I'm sending an object (emailField) to an EJS file for rendering. It doesn't throw an error but the output is unexpected and I'm not sure why I'm getting double "".

The Express route:

app.get('/my_form', function(req, res, next){

    emailField = {
        attributes: 'type=\"email\" minLength=\"5\" maxLength=\"50\" autofocus'

        \\ same output if I use single quote "
        \\ attributes: 'type="email" minLength="5" maxLength="50" autofocus'
    }

    res.render('my_form', emailField);
});

From my_form EJS:

<input <%= emailField.attributes %>>

The output in Chrome:

<input type=""email"" minlength=""5"" maxlength=""50"" autofocus>
Related
Convert character to ASCII code in JavaScript
How can I merge properties of two JavaScript objects dynamically?
When to use double or single quotes in JavaScript?
Compare two dates with JavaScript
JavaScript chop/slice/trim off last character in string
Generate random string/characters in JavaScript
How to merge two arrays in JavaScript and de-duplicate items
Generate random number between two numbers in JavaScript
Why doesn’t Postman get a “No 'Access-Control-Allow-Origin' header is present on the requested resource” error when my JavaScript code does?