首页>>新闻中心>>ES6学习方法

模板字符串

来源: 本站    发布时间: 2021-02-27 23:11    阅读次数:

console.log("\z" === "z")  //
    console.log("\172" === "z")  //八进制
    //\xHH 十六进制
    console.log("\x7A".toString()) //z
    //模板字符串
    // const str1 = "你好好\n" +
    //     "世界杯\n" +
    //     "法国世界杯冠军"
    // console.log(str1)
    // let a = 20
    // let b = 14
    // let str2 = `${str1} ${a+b}
    // 我不知道
    // 你说的什么`
    // console.log(str2)
    // 嵌套模板
    const isLargeScreen = ()=>{
        return false
    }
    let class1 = "icon"
    class1 += isLargeScreen() ? ' icon-big': ' icon-small'
    console.log(class1)
    const class2 = `icon icon-${isLargeScreen()?"big":"small"}`
    console.log(class2)
    //模板字符串
    const foo = (a, b, c, d) =>{
        console.log(a) //数组 没有替换变量的值
        console.log(b) // 严钢
        console.log(c) // 34
        console.log(d) // 123
    }
    const name = "严钢"
    const age = 34
    foo`这是${name},她的年龄${age}${123}`
    console.log(String.fromCharCode(0x20BB7))
    const str = "design"
    console.log(str.indexOf("es")) //-1
    console.log(str.includes("es")) //true
    console.log(str.startsWith("de") + str.endsWith("n")) // true + true
    const newStr = str.repeat(10) //重复10次
    console.log(newStr)
一起设计吧
上一篇: ES6 map数据结构
BACK