javascripttemplate-literals

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?


Solution

  • 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, ($)