freeCodeCamp/guide/chinese/certifications/javascript-algorithms-and-d.../basic-javascript/constructing-strings-with-v.../index.md

433 B

title localeTitle
Constructing Strings with Variables 用变量构造字符串

用变量构造字符串

添加存储字符串的变量,以创建更长的字符串。确保你的拼写和间距是正确的。

var myName = "Bobby"; 
 var myFavLetter = "B"; 
 var sentence = "Hello, I'm " + myName + ". My favorite letter is " + myFavLetter + "."; 
  //The result is "Hello, I'm Bobby. My favorite letter is B.