Template Literals

Does App Lab allow the use of template literals? I have a student learning JS outside of code.org. We are learning string concatenation and he tried to do the following but it didn’t work:
var age = 18;
console.log(Age is ${age});

Any advice?

String concatenation and string interpolation are different concepts. In your case, concatenating the string would be

console.log("Age is "+age);

while its interpolated equivalent is

console.log(`Age is ${age}`);

String interpolation and template literals were introduced in ES6. Applab is in ES5, so it looks like you’ll have to settle for normal concatenation.

Thank you ismailmf77 for your quick reply and explanation!

1 Like