Sadowbass
Sadowbass

Reputation: 23

template literal dosn't work except backslash

let str = 'asdwazsgdsadf' + 'qetgsadfdf';
let str2 = `asdqwedd		qrqwee
fqfqw
qrwrq`;
    		
let v1 = 100;
let v2 = 200;
let v3 = v1 * v2;
let str3 = `\${v1} * \${v2} = \${v3}`;
let t1 = 'hong'

console.log('v1 : ', `${v1}`); // out = v1 : 
console.log('t1 : ', `${t1}`); // out = t1 : 
console.log('str2 : ', str2);
console.log('str3 : ', str3); // out = str3 :  100 * 200 = 20000

this is my template literal test code.
other people can use ${v1} but my code is look like null.

what's matter of this code?

Upvotes: -1

Views: 61

Answers (2)

pope_maverick
pope_maverick

Reputation: 980

with

`${v1} * ${v2} = ${v3}`

you should get the console log:

"100 * 200 = 20000"

but, whenever u add that backslash it takes away the speciality of the immediate special character followed by it , in your case, ($)

Upvotes: 1

tylerwillis
tylerwillis

Reputation: 119

Without knowing more I'd say that you should check your environment to be sure that it can run template literals.

Check this list: CanIUse

Upvotes: 2

Related Questions