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>

輸出的結果如下
在這裏插入圖片描述
拜拜週末愉快

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章