JavaScript Format String
JavaScript Format String
The format string is composed of some operands and made to generate a real string by arguments. There are many programming language with the official format string method; for example, in C, it can use sscanf within %d, %s, %f, etc. to stand for the type from the auguments; similarly, in Python, it can use string.format within ${0}, ${1}, etc. to represent the order of the coming arguments.
Fortunately, in JavaScript, there is a method similar to those modern languages. However, the format string is a little different from the general string. The difference is using the graven accent instead of the quotation marks. The usage is like the following:
1 | var a = 10; |
1 | var b = ‘hello world’; |
1 | var s = ` test ${a} ${b}`; |
Now, you can use the string be composed of the arguments.
Originally published on Medium