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.

26th Dec 2017, 5:35 AM
Yasir Taj
Yasir Taj - avatar
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 + "."
26th Dec 2017, 5:53 AM
Dev
Dev - avatar
+ 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}`);
26th Dec 2017, 6:35 AM
ChaoticDawg
ChaoticDawg - avatar
+ 2
lol, ya I did say back tics in my post. 😉
27th Dec 2017, 3:44 AM
ChaoticDawg
ChaoticDawg - avatar
0
That is a backtick not a single quote.... wow I feel so dumb!
27th Dec 2017, 3:42 AM
Yasir Taj
Yasir Taj - avatar
0
exactly... lol
27th Dec 2017, 12:12 PM
Yasir Taj
Yasir Taj - avatar