※ 物件導向程式設計-OPP(四)

閱讀時間約 1 分鐘

※ 模板字串(template literal):

  • 使用「``」作為語法,作為字串拼接。
  • 呈現多行內容。
const multiLineString = `This is a string
that spans multiple
lines.`
console.log(multiLineString)
/*
This is a string
that spans multiple
lines.
*/
  • 可使用${var}嵌套變數和任意表達式。
const a = 5
const b = 10
const result = `The sum of ${a} and ${b} is ${a + b}.`
console.log(result) // The sum of 5 and 10 is 15.
  • 調用函數
function greet(name) {
return `Hello, ${name}`
}

const message = `${greet('Bob')}! How are you?`
console.log(message) // Hello, Bob! How are you?
    全端網頁開發專業知識分享
    留言0
    查看全部
    發表第一個留言支持創作者!
    你可能也想看
    Google News 追蹤
    Thumbnail
    本專欄將提供給您最新的市場資訊、產業研究、交易心法、精選公司介紹,以上內容並非個股分析,還請各位依據自身狀況作出交易決策。歡迎訂閱支持我,獲得相關內容,也祝您的投資之路順遂! 每年 $990 訂閱方案👉 https://reurl.cc/VNYVxZ 每月 $99 訂閱方案👉https://re
    Thumbnail
    本專欄將提供給您最新的市場資訊、產業研究、交易心法、精選公司介紹,以上內容並非個股分析,還請各位依據自身狀況作出交易決策。歡迎訂閱支持我,獲得相關內容,也祝您的投資之路順遂! 每年 $990 訂閱方案👉 https://reurl.cc/VNYVxZ 每月 $99 訂閱方案👉https://re