본문 바로가기

Python_WEB/JavaScript

[freecodecamp]JavaScript 이스케이프 이중따옴표

반응형

문자열을 정의 할 때 작은 따옴표나 큰 따옴표로 시작하고 끝나야합니다.

문자열 안에 리터럴 따옴표 ( "또는 ')가 필요하면 어떻게됩니까?

JavaScript에서는 따옴표 앞에 백 슬래시 (\)를 배치하여 따옴표를 문자열 따옴표의 끝으로 간주하지 않도록 이스케이프 할 수 있습니다.

 

var sampleStr = "Alan said, \"Peter is learning JavaScript\".";

 

이는 다음 따옴표가 문자열의 끝이 아니라 대신 문자열 안에 나타나야 함을 JavaScript에 알립니다.

따라서 이것을 콘솔에 인쇄하면 다음을 얻을 수 있습니다.

 

Alan said, "Peter is learning JavaScript".

 

Q>

1. 백 슬래시를 사용하여 myStr 변수에 문자열을 할당하면 콘솔에 인쇄 할 경우 다음과 같이 표시됩니다.

 

I am a "double quoted" string inside "double quotes".

 

2. 두 개의 큰 따옴표 (")와 네 개의 이스케이프 된 큰 따옴표 (\")를 사용해야합니다.

3, myStr 변수는 다음 문자열을 포함해야합니다.

 

I am a "double quoted" string inside "double quotes".

 

A>

var myStr = "I am a \"double quoted\" string inside \"double quotes\"."; // Change this line

 

https://www.freecodecamp.org/

 

freeCodeCamp.org

Learn to code. Build projects. Earn certifications.Since 2015, 40,000 graduates have gotten jobs at tech companies including Google, Apple, Amazon, and Microsoft.

www.freecodecamp.org

 

반응형