hrishikeshp19
hrishikeshp19

Reputation: 9026

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.

Upvotes: 0

Views: 8383

Answers (2)

勿绮语
勿绮语

Reputation: 9330

Escape one or the other:

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

Upvotes: 3

Cᴏʀʏ
Cᴏʀʏ

Reputation: 107576

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)

Upvotes: 3

Related Questions