I'm not too sure if I've seen it before, I think in CoffeScript . A way to write string using variables or arguments like C# for example.
var nombre = "Jesse";
var text1 = $"Hola, me llamo {nombre}";
var text2 = string.Format("Hola, me llamo {0}", nombre);
If it is possible in JavaScript I would like to know how I can do it. I have been searching the internet for a long time and I have not found anything related.
The current code is the following
function getDimensions(item)
{
return "{item.css('padding-left')} {item.css('padding-top')} {item.css('padding-right')} {item.css('padding-bottom')}";
}
// output: {item.css('padding-left')} {item.css('padding-top')} {item.css('padding-right')} {item.css('padding-bottom')}
The objective is '10,5,30,0'
to obtain the paddin of an element. I am using jQuery.
They are known as template strings .
You replace the normal string delimiters with a symbol called a backtick
`
.They can be dangerous because they adapt to what you put by automatically adding line breaks if the content implicitly has them, that is, even if you don't put
\n
.To escape the executable text you put it inside the braces of the construct
${}
.for instance
This form is known as interpolation.
Javascript doesn't natively support traditional formatting, if you need to use it, you can use a library like sprintf to avoid coding the code yourself.
As Ruslan López mentions to you. One possible way to do this is to use `` to delimit strings. As follows:
Another way is to implement your own function that allows you to do that, depending on what you need to solve: