Top

01. 문자열 : 문자열 결합 / 템플릿 문자열

번호 기본값 속성 결괏값
{
    const str1 = "자바스크립트";
    const str2 = "제이쿼리";

    document.querySelector(".sample01_N1").innerHTML = 1;
    document.querySelector(".sample01_Q1").innerHTML = "자바스크립트, 제이쿼리";
    document.querySelector(".sample01_M1").innerHTML = "string 결합";
    document.querySelector(".sample01_R1").innerHTML = str1 + str2;

    const num1 = 100;
    const num2 = 200;

    document.querySelector(".sample01_N2").innerHTML = 2;
    document.querySelector(".sample01_Q2").innerHTML = "100, 200";
    document.querySelector(".sample01_M2").innerHTML = "number 결합";
    document.querySelector(".sample01_R2").innerHTML = num1 + num2;

    const txt1 = "모던";
    const txt2 = " 자바스크립트";
    const txt3 = "핵심";

    // 나는모던 (modern) 자바스크립트(javascript) 핵심을 배우고 싶다.
    document.querySelector(".sample01_N3").innerHTML = 3;
    document.querySelector(".sample01_Q3").innerHTML = "모던, 자바스크립트, 핵심";
    document.querySelector(".sample01_M3").innerHTML = "문자열 결합";
    document.querySelector(".sample01_R3").innerHTML = "나는"+txt1+"(modern)"+txt2+"(javascript)"+txt3+"을 배우고 싶다.";
    
    document.querySelector(".sample01_N4").innerHTML = 4;
    document.querySelector(".sample01_Q4").innerHTML = "모던, 자바스크립트, 핵심";
    document.querySelector(".sample01_M4").innerHTML = "템플릿 문자열";
    document.querySelector(".sample01_R4").innerHTML = `나는 ${txt1}(modern) ${txt2}(javascript) ${txt3}을 배우고 싶다.`;
}

02. 문자열 속성 : length : 문자열 길이 구하기 : 반환(숫자)

번호 기본값 속성 결괏값
{
    const str1 = "자바스크립트";
    const currenStr1 = str1.length;

    document.querySelector(".sample02_N1").innerHTML = 1;
    document.querySelector(".sample02_Q1").innerHTML = str1;
    document.querySelector(".sample02_M1").innerHTML = "length";
    document.querySelector(".sample02_R1").innerHTML = currenStr1;

    const str2 = "javascript";
    const currenStr2 = str2.length;

    document.querySelector(".sample02_N2").innerHTML = 2;
    document.querySelector(".sample02_Q2").innerHTML = str2;
    document.querySelector(".sample02_M2").innerHTML = "length";
    document.querySelector(".sample02_R2").innerHTML = currenStr2;
}

03. 문자열 메서드 : toUpperCase() : 문자열 대문자 변경 : 반환(문자열) 04. 문자열 메서드 : toLowerCase() : 문자열 소문자 변경 : 반환(문자열)

번호 기본값 속성 결괏값
{
    const str1 = "javascript";
    const currenStr1 = str1.toUpperCase();

    document.querySelector(".sample03_N1").innerHTML = 1;
    document.querySelector(".sample03_Q1").innerHTML = str1;
    document.querySelector(".sample03_M1").innerHTML = "toUpperCase();";
    document.querySelector(".sample03_R1").innerHTML = currenStr1;

    const str2 = "JAVASCRIPT";
    const currenStr2 = str2.toLowerCase();

    document.querySelector(".sample03_N2").innerHTML = 2;
    document.querySelector(".sample03_Q2").innerHTML = str2;
    document.querySelector(".sample03_M2").innerHTML = "toLowerCase();";
    document.querySelector(".sample03_R2").innerHTML = currenStr2;
}

05. 문자열 메서드 : trim() : 문자열 공백 제거 : 반환(문자열)

번호 기본값 속성 결괏값
{
    const str1 = "           'javascript'          ";
    const currenStr1 = str1.trim();

    document.querySelector(".sample04_N1").innerHTML = 1;
    document.querySelector(".sample04_Q1").innerHTML = str1;
    document.querySelector(".sample04_M1").innerHTML = "trim();";
    document.querySelector(".sample04_R1").innerHTML = currenStr1;
}

06. 07. 08. 09. 10. 11문자열 메서드 : indexOf() / lastIndexOf() / search() / includes() / startsWidth() / endWidth(): 문자열 검색 : 반환(숫자)

번호 기본값 속성 결괏값
{
    const str = "자바스크립트(javascript) 공부";

    const text1 = str.indexOf("javascript");

    document.querySelector(".sample05_N1").innerHTML = 1;
    document.querySelector(".sample05_Q1").innerHTML = str;
    document.querySelector(".sample05_M1").innerHTML = "indexOf('javascript');";
    document.querySelector(".sample05_R1").innerHTML = text1;

    const text2 = str.indexOf("자바스크립트");

    document.querySelector(".sample05_N2").innerHTML = 2;
    document.querySelector(".sample05_Q2").innerHTML = str;
    document.querySelector(".sample05_M2").innerHTML = "indexOf('자바스크립트');";
    document.querySelector(".sample05_R2").innerHTML = text2;

    const text3 = str.indexOf("제이쿼리");

    document.querySelector(".sample05_N3").innerHTML = 3;
    document.querySelector(".sample05_Q3").innerHTML = str;
    document.querySelector(".sample05_M3").innerHTML = "indexOf('제이쿼리');";
    document.querySelector(".sample05_R3").innerHTML = text3;

    const text4 = str.indexOf("a");

    document.querySelector(".sample05_N4").innerHTML = 4;
    document.querySelector(".sample05_Q4").innerHTML = str;
    document.querySelector(".sample05_M4").innerHTML = "indexOf('a');";
    document.querySelector(".sample05_R4").innerHTML = text4;

    const text5 = str.lastIndexOf("a");

    document.querySelector(".sample05_N5").innerHTML = 5;
    document.querySelector(".sample05_Q5").innerHTML = str;
    document.querySelector(".sample05_M5").innerHTML = "lastIndexOf('a');";
    document.querySelector(".sample05_R5").innerHTML = text5;

    const text6 = str.search(/javascript/);

    document.querySelector(".sample05_N6").innerHTML = 6;
    document.querySelector(".sample05_Q6").innerHTML = str;
    document.querySelector(".sample05_M6").innerHTML = "search(/javascript/);";
    document.querySelector(".sample05_R6").innerHTML = text6;

    const text7 = str.search(/jquery/);

    document.querySelector(".sample05_N7").innerHTML = 7;
    document.querySelector(".sample05_Q7").innerHTML = str;
    document.querySelector(".sample05_M7").innerHTML = "search(/jquery/);";
    document.querySelector(".sample05_R7").innerHTML = text7;

    const text8 = str.includes("javascript");

    document.querySelector(".sample05_N8").innerHTML = 8;
    document.querySelector(".sample05_Q8").innerHTML = str;
    document.querySelector(".sample05_M8").innerHTML = "includes('javascript');";
    document.querySelector(".sample05_R8").innerHTML = text8;

    const text9 = str.includes("jquery");

    document.querySelector(".sample05_N9").innerHTML = 9;
    document.querySelector(".sample05_Q9").innerHTML = str;
    document.querySelector(".sample05_M9").innerHTML = "includes('jquery);";
    document.querySelector(".sample05_R9").innerHTML = text9;

    const text10 = str.endsWith("자바스크립트");

    document.querySelector(".sample05_N10").innerHTML = 10;
    document.querySelector(".sample05_Q10").innerHTML = str;
    document.querySelector(".sample05_M10").innerHTML = "endsWith('자바스크립트');";
    document.querySelector(".sample05_R10").innerHTML = text10;

    const text11 = str.endsWith("javascript");

    document.querySelector(".sample05_N11").innerHTML = 11;
    document.querySelector(".sample05_Q11").innerHTML = str;
    document.querySelector(".sample05_M11").innerHTML = "endsWith('javascript);";
    document.querySelector(".sample05_R11").innerHTML = text11;
}

12. 문자열 메서드 : charAt() : 지정한 인덱스의 문자를 추출

번호 기본값 속성 결괏값
{
        const str = "자바스크립트(javascript) 공부";
        const text = str.charAt(4);

        document.querySelector(".sample06_N1").innerHTML = 1;
        document.querySelector(".sample06_Q1").innerHTML = str;
        document.querySelector(".sample06_M1").innerHTML = "charAt(4);";
        document.querySelector(".sample06_R1").innerHTML = text;

        const text2 = str.charAt();

        document.querySelector(".sample06_N2").innerHTML = 2;
        document.querySelector(".sample06_Q2").innerHTML = str;
        document.querySelector(".sample06_M2").innerHTML = "charAt();";
        document.querySelector(".sample06_R2").innerHTML = text2;
}

13. 14. 15. 문자열 메서드 : slice() / substring() / substr(): 지정한 범위 내 문자열을 추출

번호 기본값 속성 결괏값
{
    // sample07
    // slice(시작 인덱스)
    // slice(시작 인덱스, 종료 인덱스)
    // slice : 시작 값이 종료 값보다 클 경우 : 결과 값 없음
    // substring() :시작 값이 종료 값보다 클 경우 : 두 값을 바꿔서 처리
    // substr(시작인덱스, 글자수)

    const str = "자바스크립트(javascript) 공부";

    const text = str.slice(1, 4);

    document.querySelector(".sample07_N1").innerHTML = 1;
    document.querySelector(".sample07_Q1").innerHTML = str;
    document.querySelector(".sample07_M1").innerHTML = "slice(1, 4);";
    document.querySelector(".sample07_R1").innerHTML = text;

    const text2 = str.slice(1);

    document.querySelector(".sample07_N2").innerHTML = 2;
    document.querySelector(".sample07_Q2").innerHTML = str;
    document.querySelector(".sample07_M2").innerHTML = "slice(1);";
    document.querySelector(".sample07_R2").innerHTML = text2;

    const text3 = str.slice(3, -1);

    document.querySelector(".sample07_N3").innerHTML = 3;
    document.querySelector(".sample07_Q3").innerHTML = str;
    document.querySelector(".sample07_M3").innerHTML = "slice(3, -1);";
    document.querySelector(".sample07_R3").innerHTML = text3;

    const text4 = str.slice(7, 17);
    //const text4 = str.slice(7, -4);
    //const text4 = str.slice(-14, -4);
    //const text4 = str.slice(-14, 17);

    document.querySelector(".sample07_N4").innerHTML = 4;
    document.querySelector(".sample07_Q4").innerHTML = str;
    document.querySelector(".sample07_M4").innerHTML = "slice(7, 17);";
    document.querySelector(".sample07_R4").innerHTML = text4;

    const text5 = str.slice(5, 1);

    document.querySelector(".sample07_N5").innerHTML = 5;
    document.querySelector(".sample07_Q5").innerHTML = str;
    document.querySelector(".sample07_M5").innerHTML = "slice(5, 1);";
    document.querySelector(".sample07_R5").innerHTML = "실행 안됨";

    const text6 = str.substring(5, 1);
    // subString() :시작 값이 종료 값보다 클 경우 : 두 값을 바꿔서 처리
    document.querySelector(".sample07_N6").innerHTML = 6;
    document.querySelector(".sample07_Q6").innerHTML = str;
    document.querySelector(".sample07_M6").innerHTML = "substring(5, 1);";
    document.querySelector(".sample07_R6").innerHTML = text6;

    const text7 = str.substr(4, 2);
    
    document.querySelector(".sample07_N7").innerHTML = 7;
    document.querySelector(".sample07_Q7").innerHTML = str;
    document.querySelector(".sample07_M7").innerHTML = "substr(4, 2);";
    document.querySelector(".sample07_R7").innerHTML = text7;  
}

16. 문자열 메서드 : replace() : 지정한 범위 내 문자열을 추출 : 반환(문자열)

번호 기본값 속성 결괏값
{
    const str = "자바스크립트(javascript) 공부";
    const text = str.replace('공부', '스터디');

    document.querySelector(".sample08_N1").innerHTML = 1;
    document.querySelector(".sample08_Q1").innerHTML = str;
    document.querySelector(".sample08_M1").innerHTML = "replace('공부', '스터디')";
    document.querySelector(".sample08_R1").innerHTML = text;

    const str2 = "img01.jpg";
    const text2 = str2.replace('img01.jpg', 'img02.jpg');

    document.querySelector(".sample08_N2").innerHTML = 2;
    document.querySelector(".sample08_Q2").innerHTML = str2;
    document.querySelector(".sample08_M2").innerHTML = "replace('img01.jpg', 'img02.jpg')";
    document.querySelector(".sample08_R2").innerHTML = text2;

    const str3 = "010-2406-8904";
    const text3 = str3.replace('-', '');

    document.querySelector(".sample08_N3").innerHTML = 3;
    document.querySelector(".sample08_Q3").innerHTML = str3;
    document.querySelector(".sample08_M3").innerHTML = "replace('-', '')";
    document.querySelector(".sample08_R3").innerHTML = text3;

    const str4 = "010-2406-8904";
    const text4 = str4.replace(/-/g, ''); // g : 글로벌 : 전체 선택

    document.querySelector(".sample08_N4").innerHTML = 4;
    document.querySelector(".sample08_Q4").innerHTML = str4;
    document.querySelector(".sample08_M4").innerHTML = "replace(/-/g, '')";
    document.querySelector(".sample08_R4").innerHTML = text4;

    const str5 = "010-2406-8904";
    const text5 = str5.replace(/-/g, ' '); // g : 글로벌 : 전체 선택

    document.querySelector(".sample08_N5").innerHTML = 5;
    document.querySelector(".sample08_Q5").innerHTML = str5;
    document.querySelector(".sample08_M5").innerHTML = "replace(/-/g, ' ')";
    document.querySelector(".sample08_R5").innerHTML = text5;   
}

17. 문자열 메서드 : split() : 문자열 반환 : 반환(문자열)

번호 기본값 속성 결괏값
{
    const str = "자바스크립트(javascript) 공부";
    const text = str.split('');

    document.querySelector(".sample09_N1").innerHTML = 1;
    document.querySelector(".sample09_Q1").innerHTML = str;
    document.querySelector(".sample09_M1").innerHTML = "split('')";
    document.querySelector(".sample09_R1").innerHTML = text;

    const text2 = str.split(' ');

    document.querySelector(".sample09_N2").innerHTML = 2;
    document.querySelector(".sample09_Q2").innerHTML = str;
    document.querySelector(".sample09_M2").innerHTML = "split(' ')";
    document.querySelector(".sample09_R2").innerHTML = text2;

    const text3 = str.split('').join('/');

    document.querySelector(".sample09_N3").innerHTML = 3;
    document.querySelector(".sample09_Q3").innerHTML = str;
    document.querySelector(".sample09_M3").innerHTML = "split(' ').join('/')";
    document.querySelector(".sample09_R3").innerHTML = text3;

    const str4 = "http://jowunseop.co.kr/main.html?id=1234&name=webs";
    const text4 = str4.split('&');

    document.querySelector(".sample09_N4").innerHTML = 4;
    document.querySelector(".sample09_Q4").innerHTML = str4;
    document.querySelector(".sample09_M4").innerHTML = "split('&');";
    document.querySelector(".sample09_R4").innerHTML = text4;

    
    const str5 = "http://jowunseop.co.kr/main.html?id=1234&name=webs";
    const text5 = str5.split(/&|\?/);

    document.querySelector(".sample09_N5").innerHTML = 5;
    document.querySelector(".sample09_Q5").innerHTML = str5;
    document.querySelector(".sample09_M5").innerHTML = "split(/&|\?/);";
    document.querySelector(".sample09_R5").innerHTML = text5;                      
}

18. 문자열 메서드 : padStart() : 문자열 시작 부분에 문자열 추가 : 반환(문자열)
19. 문자열 메서드 : padEnd() : 문자열 끝 부분에 문자열 추가 : 반환(문자열)

번호 기본값 속성 결괏값
{
    const num = "7";
    const text = num.padStart(2, '0');

    document.querySelector(".sample10_N1").innerHTML = 1;
    document.querySelector(".sample10_Q1").innerHTML = num;
    document.querySelector(".sample10_M1").innerHTML = "padStart(2, '0')";
    document.querySelector(".sample10_R1").innerHTML = text

    const num2 = "456";
    const text2 = num2.padStart(6, '123');

    document.querySelector(".sample10_N2").innerHTML = 2;
    document.querySelector(".sample10_Q2").innerHTML = num2;
    document.querySelector(".sample10_M2").innerHTML = "padStart(6, '123')";
    document.querySelector(".sample10_R2").innerHTML = text2

    const num3 = "abc";
    const text3 = num3.padStart(3, '0');

    document.querySelector(".sample10_N3").innerHTML = 3;
    document.querySelector(".sample10_Q3").innerHTML = num3;
    document.querySelector(".sample10_M3").innerHTML = "padStart(3, '0')";
    document.querySelector(".sample10_R3").innerHTML = text3

    const num4 = "abc";
    const text4 = num4.padStart(6);

    document.querySelector(".sample10_N4").innerHTML = 4;
    document.querySelector(".sample10_Q4").innerHTML = num4;
    document.querySelector(".sample10_M4").innerHTML = "padStart(6)";
    document.querySelector(".sample10_R4").innerHTML = "
'" + text4 + "'
"; const num5 = "7"; const text5 = num5.padStart(2, 0); document.querySelector(".sample10_N5").innerHTML = 5; document.querySelector(".sample10_Q5").innerHTML = num5; document.querySelector(".sample10_M5").innerHTML = "padStart(2, '0')"; document.querySelector(".sample10_R5").innerHTML = text5; const num6 = "456"; const text6 = num6.padStart(6, 123); document.querySelector(".sample10_N6").innerHTML = 6; document.querySelector(".sample10_Q6").innerHTML = num6; document.querySelector(".sample10_M6").innerHTML = "padStart(6, '123')"; document.querySelector(".sample10_R6").innerHTML = text6; const num7 = "abc"; const text7 = num7.padStart(3, '0'); document.querySelector(".sample10_N7").innerHTML = 7; document.querySelector(".sample10_Q7").innerHTML = num7; document.querySelector(".sample10_M7").innerHTML = "padStart(3, '0')"; document.querySelector(".sample10_R7").innerHTML = text7; const num8 = "456"; const text8 = num8.padStart(6); document.querySelector(".sample10_N8").innerHTML = 8; document.querySelector(".sample10_Q8").innerHTML = num8; document.querySelector(".sample10_M8").innerHTML = "padStart(6)"; document.querySelector(".sample10_R8").innerHTML = "
'" + text8 + "'
"; }

20. 문자열 메서드 : encodeURL() : 문자열 인코딩 : 반환(문자열)
21. 문자열 메서드 : encodeURLcomponent() : 문자열 인코딩 : 반환(문자열)
22. 문자열 메서드 : decodeURL() : 문자열 디코딩 : 반환(문자열)
23. 문자열 메서드 : decodeURLcomponent() : 문자열 디코딩 : 반환(문자열)

번호 기본값 속성 결괏값
{
    // URL에 한글이 포함되면 사용 할 수 없기 때문에 인코딩을 해줍니다.
    const text = "https://webstoryboy.co.kr/자바스크립트.html";
    const url = encodeURI(text);

    document.querySelector(".sample11_N1").innerHTML = "1";
    document.querySelector(".sample11_Q1").innerHTML = text;
    document.querySelector(".sample11_M1").innerHTML = "encodeURI()";
    document.querySelector(".sample11_R1").innerHTML = url;

    const text2 = "https://webstoryboy.co.kr/자바스크립트.html";
    const url2 = encodeURIComponent(text2);

    document.querySelector(".sample11_N2").innerHTML = "2";
    document.querySelector(".sample11_Q2").innerHTML = text2;
    document.querySelector(".sample11_M2").innerHTML = "encodeURIComponent()";
    document.querySelector(".sample11_R2").innerHTML = url2;

    const text3 = "https://webstoryboy.co.kr/%EC%9E%90%EB%B0%94%EC%8A%A4%ED%81%AC%EB%A6%BD%ED%8A%B8.html";
    const url3 = decodeURI(text3);

    document.querySelector(".sample11_N3").innerHTML = "3";
    document.querySelector(".sample11_Q3").innerHTML = text3;
    document.querySelector(".sample11_M3").innerHTML = "decodeURI()";
    document.querySelector(".sample11_R3").innerHTML = url3;

    const text4 = "https%3A%2F%2Fwebstoryboy.co.kr%2F%EC%9E%90%EB%B0%94%EC%8A%A4%ED%81%AC%EB%A6%BD%ED%8A%B8.html";
    const url4 = decodeURIComponent(text4);

    document.querySelector(".sample11_N4").innerHTML = "4";
    document.querySelector(".sample11_Q4").innerHTML = text4;
    document.querySelector(".sample11_M4").innerHTML = "decodeURIComponent()";
    document.querySelector(".sample11_R4").innerHTML = url4;               
}

번호 기본값 속성 결괏값
{
                
                      
        }

번호 기본값 속성 결괏값
{
                
                      
        }