天天看點

ES6核心文法整理筆記(三)模闆字元串

模闆字元串使用

今天的内容簡短一些,直接上題感受es6模闆字元串的寫法

ES6核心文法整理筆記(三)模闆字元串

這是我的解法

<script>
    const weather ={
        city:"廣州市",
        temperature:27,
        humidity:"94%"
    }

    const weatherForecast = "下面為您播報一則天氣" + weather.city + ",氣溫" + weather.temperature +"度,濕度為" + weather.humidity+"。";
    console.log(weatherForecast)
    const weatherForecast1=`下面為您播報一則天氣${weather.city},氣溫${weather.temperature}度,濕度為${weather.humidity}。`
    console.log(weatherForecast1)

    var X

    function calc(x){
        return `你輸入的是{${x}},它的兩倍是{${2*x}},它的平方是${x*x}`;
    }
    console.log(calc(5))
</script>
           

輸出的結果如下

ES6核心文法整理筆記(三)模闆字元串

拜拜周末愉快