ES6中新增字符串方法,字符串模板

多了两个新方法
startsWith
endsWith

返回的是一个Boolean值

        let str='git://www.baidu.com/2123123';
        if(str.startsWith('http://')){
            alert('普通网址');
        }else if(str.startsWith('https://')){
            alert('加密网址');
        }else if(str.startsWith('git://')){
            alert('git地址');
        else{
          alert('其他');
        }
`(反单引号也称重音符 位置在键盘左上角的位置~)

let a=12;

let str=`a${a}bc`;

直接把东西塞到字符串里面 ${东西}

        let title='标题';
        let content='内容';
        let str='<div>
      <h1>'+title+'</h1>
      <p>'+content+'</p>
    </div>';
        //这么拼字符串不在加反斜杠这个转义字符了
        let str2=`<div>
          <h1>${title}</h1>
         <p>${content}</p>
        </div>`;
        alert(str2)
原文地址:https://www.cnblogs.com/tianranhui/p/9216188.html