I'm new to JS and I want to know how to print a var inside a string , i found that the way should be :
var user = {
name: "Mike",
sayHi:() => {
console.log('Hi, I\'m ${name}');
}
};
user.sayHi()
but I get : Hi, I'm ${name}
You can specify your variables directly in the strings. $message = "Hello, $first $last." The type of quotes you use around the string makes a difference. A double quoted string allows the substitution but a single quoted string doesn't.
To print the variable in Java, there are three print methods of the System class: print(), println(), and printf() methods. The print() method prints out all statements in a single line. Whereas the println() method prints the value of the added variables or text in separate lines.
Template literals use backticks `` instead of regular quotes ''.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With