※ 物件導向程式設計-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?
全端網頁開發專業知識分享
留言
avatar-img
留言分享你的想法!

































































你可能也想看
從 Google News 追蹤更多 vocus 的最新精選內容