sprewell20051116 / JavascriptCourse

讀書會提出問題的平台
0 stars 2 forks source link

Subject 05 Class 41 - ${a} not working #7

Open sprewell20051116 opened 7 years ago

sprewell20051116 commented 7 years ago
// Template Literals
let a = "good";
let greeting_41 = "good morning";
let greeting_41_2 = "${a} morning";
console.log(a);
console.log(greeting_41);
console.log(greeting_41_2);

最後輸出

good
good morning
${a} morning

課程中希望是可以使用 ${a} 來替代前面已經宣告過的 let a = "good"
但是卻沒有成功

sprewell20051116 commented 7 years ago

結果是要用這個符號 "`" 左上角 1 左邊的那個按鍵。

-    let a = "good";
+    let a = `good`;
-    let greeting_41 = "good morning";
+    let greeting_41 = `good morning`;
-    let greeting_41_2 = "${a} morning";
+    let greeting_41_2 = `${a} morning`;
console.log(a);
console.log(greeting_41);
console.log(greeting_41_2);

就可以成功輸出

good
good morning
good morning