0
How do i add a variable within a string block ? For example: " my name is + myVar+ and I age is + age+."
I don't know if the question makes any sense.
5 Réponses
+ 8
Close the double quotes before the "+" symbol, otherwise it all would become a String.
"my name is " + myVar + " and my age is " + age + "."
+ 4
You could also do it the ES6 way by using back tics.
let myVar = "Somebody";
let age = 42;
alert(`My name is ${myVar} and I am ${age}`);
+ 2
lol, ya I did say back tics in my post. 😉
0
That is a backtick not a single quote.... wow I feel so dumb!
0
exactly... lol