Skip to content Skip to sidebar Skip to footer

Representing Single And Double Quotation Marks In A String Literal

I want to represent height in this format in javascript 6'00' I tried this var height = '6'+'''+'00''; which works Is there a cleaner way? Thanks.

Solution 1:

Escape one or the other:

"6'00\""
'6\'00"'

Solution 2:

If you surround your text with single quotes, you need to escape the inner single quote, or if you surround your text with double quotes, you need to escape the inner double quote. Here are the two flavors:

var height = '6\'00"';

Or

var height = "6'00\"";

You could also use an HTML encoded version if you'd like:

var height = '6'00"';

(JSFiddle Example)


Post a Comment for "Representing Single And Double Quotation Marks In A String Literal"