I am new to JS and I want to know how to print var inside a string, I found that the path should be:
var user = { name: "Mike", sayHi:() => { console.log('Hi, I\'m ${name}'); } }; user.sayHi()
but I get: Hi, I'm ${name}
Hi, I'm ${name}
Template literals use backreferences `` instead of regular quotes. ''
If you want to use variables in a string, you must wrap them with reverse `ticks' instead of double or single quotes.
So the example below:
console.log(`Hi, I'm ${name}`);
('') (``) .
var user = { name: "Mike", sayHi:() => { console.log(`Hi, I\'m ${user.name}`); } }; user.sayHi()
`backquote. Single quote '
EDIT: @peteb ,
console.log('Hi, I\'m ' + name);
This should be the back tick of a single quote. Below you will find
var user = { name: "Mike", sayHi:() => { console.log(`Hi, I\'m ${name}`); } }; user.sayHi()
Source: https://habr.com/ru/post/1695165/More articles:Python: analyze list comprehension with - performanceChanging the path of an ActiveStorage controller - ruby-on-railsGit checkout -p Regular Expression Search HEAD - gitJava 8: Despite the fact that you avoid the work of the terminal, see "The thread has already been operated or is closed" - java-8Use java argument parameter in IntelliJ - javaGet the waterfall category names - vbaHow to invalidate all entries except argmax? - pythonGet form by identifier or name - vbaGet form ID by name - vbaHow to disable "Use strict mode for URI forwarding" in facebook application - facebookAll Articles