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

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

    document.querySelector(".sample01_R1").innerHTML = str1 + str2;

    const num1 = 100;
    const num2 = 200;

    document.querySelector(".sample01_R2").innerHTML = num1 + num2;

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

    document.querySelector(".sample01_R3").innerHTML = "나는 " + txt1 + "(modern)" + txt2 + "(javascript) " + txt3 + "을 배우고 싶다";

    const tem1 = "모던";
    const tem2 = "자바스크립트";
    const tem3 = "핵심";

    document.querySelector(".sample01_R4").innerHTML = `나는 ${tem1}(modern) ${tem2}(javascript) ${tem3}을 배우고 싶다`;
}

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

번호 기본값 메서드 결괏값
{
    const str1 = "자바스크립트";
    const currentStr1 = str1.length;

    document.querySelector(".sample02_R1").innerHTML = currentStr1;

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

    document.querySelector(".sample02_R2").innerHTML = currentStr2;
}

03. 문자열 메서드 : toUpperCase() / toLowerCase() : 반환(문자열)

번호 기본값 메서드 결괏값
{
    const str1 = "javascript";
    const currentStr1 = str1.toUpperCase();

    document.querySelector(".sample03_R1").innerHTML = currentStr1;

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

    document.querySelector(".sample03_R2").innerHTML = currentStr2;
}

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

번호 기본값 메서드 결괏값
{
    const str1 = "     ' javascript '      ";
    const currentStr1 = str1.trim();

    document.querySelector(".sample04_R1").innerHTML = currentStr1;
}

05. 문자열 메서드 : indexOf() / lastIndexOf() / search() / includes() / startsWith() / endsWith() : 문자열 검색

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

    const text1 = str.indexOf("javascript");
    document.querySelector(".sample05_R1").innerHTML = text1;

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

    const text3 = str.indexOf("제이쿼리");
    document.querySelector(".sample05_R3").innerHTML = text3;

    const text4 = str.indexOf('a');
    document.querySelector(".sample05_R4").innerHTML = text4;

    const text5 = str.lastIndexOf('a');
    document.querySelector(".sample05_R5").innerHTML = text5;

    const text6 = str.search(/javascript/);
    document.querySelector(".sample05_R6").innerHTML = text6;

    const text7 = str.search(/jquery/);
    document.querySelector(".sample05_R7").innerHTML = text7;

    const text8 = str.includes("javascript");
    document.querySelector(".sample05_R8").innerHTML = text8;

    const text9 = str.includes("jquery");
    document.querySelector(".sample05_R9").innerHTML = text9;

    const text10 = str.startsWith("자바스크립트");
    document.querySelector(".sample05_R10").innerHTML = text10;

    const text11 = str.endsWith("javascript");
    document.querySelector(".sample05_R11").innerHTML = text11;   
}

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

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

    document.querySelector(".sample06_R1").innerHTML = text;

    const text2 = str.charAt();

    document.querySelector(".sample06_R2").innerHTML = text2;
}

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

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

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

    const text2 = str.slice(1);
    document.querySelector(".sample07_R2").innerHTML = text2;


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

    const text4 = str.slice(-14,-4);
    document.querySelector(".sample07_R4").innerHTML = text4;

    const text5 = str.slice(5, 1);
    document.querySelector(".sample07_R5").innerHTML = "실행 안됨";

    const text6 = str.substring(5, 1);
    document.querySelector(".sample07_R6").innerHTML = text6;

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