This is a feature called template literals.
They were called “template strings” in prior editions of the ECMAScript 2015 specification.
Template literals are supported by Firefox 34, Chrome 41, and Edge 12 and above, but not by Internet Explorer.
- Examples: http://tc39wiki.calculist.org/es6/template-strings/
- Official specification: ECMAScript 2015 Language Specification, 12.2.9 Template Literal Lexical Components (a bit dry)
Template literals can be used to represent multi-line strings and may use “interpolation” to insert variables:
var a = 123, str = `--- a is: ${a} ---`; console.log(str);
Output:
--- a is: 123 ---
What is more important, they can contain not just a variable name, but any JavaScript expression:
var a = 3, b = 3.1415; console.log(`PI is nearly ${Math.max(a, b)}`);
Related Posts:
- How to add a class to a given element?
- How to make a word underline in Markdown
- Creating multiline strings in JavaScript
- Babel 6 regeneratorRuntime is not defined
- What is JSONP, and why was it created?
- Remove element by id
- await is only valid in async function
- Remove duplicate values from JS array [duplicate]
- How to read an external local JSON file in JavaScript?
- SyntaxError: Unexpected token o in JSON at position 1
- Remove duplicate values from JS array
- Add swipe left/right to web page, but use default swipe up/down
- How to check if array is empty or does not exist?
- How can I convert a string to boolean in JavaScript?
- React Hook Warnings for async function in useEffect: useEffect function must return a cleanup function or nothing
- Change Background color (css property) using Jquery
- jQuery get textarea text
- Base64 encoding and decoding in client-side Javascript
- Response to preflight request doesn’t pass access control check
- Short circuit Array.forEach like calling break
- How can I check for an empty/undefined/null string in JavaScript?
- display variable image using cookies
- Find an element in DOM based on an attribute value
- character counter – backspace doesn’t reflect on characters remaining
- How does the double exclamation (!!) work in javascript?
- Use of $parse in angular js
- With jQuery, how do I capitalize the first letter of a text field while the user is still editing that field?
- Pass a JavaScript function as parameter
- Cannot read property ‘getContext’ of null, using canvas
- How to add multiple classes to a ReactJS Component?
- Make Axios send cookies in its requests automatically
- Difference between “module.exports” and “exports” in the CommonJs Module System
- Local package.json exists, but node_modules missing
- Dealing with float precision in Javascript
- JSON.parse() not working
- Call python function from JS
- How to add onload event to a div element
- Access Control Origin Header error using Axios
- Structs in Javascript
- Refused to execute script, strict MIME type checking is enabled?
- why angularjs ng-repeat not working
- jQuery remove options from select
- Convert UTC Epoch to local date
- How to execute a JavaScript function when I have its name as a string
- How to get the ASCII value in JavaScript for the characters [duplicate]
- HTML img onclick Javascript
- Clear the cache in JavaScript
- error Unable to get property ‘display’ of undefined or null reference
- Is there a php echo/print equivalent in javascript
- setInterval with loop time
- Javascript Function that returns true if a letter?
- How do I know which version of Javascript I’m using?
- getContext is not a function
- lodash multi-column sortBy
- navigator.geolocation.getCurrentPosition sometimes works sometimes doesn’t
- Expected ‘this’ to be used by class method
- Strip HTML from Text JavaScript
- Calling a JavaScript function in another js file
- JavaScript code not running in HTML5 document
- What is the cause for “angular is not defined”
- Unexpected token < in first line of HTML
- ngular is automatically adding ‘ng-invalid’ class on ‘required’ fields
- How to set “style=display:none;” using jQuery’s attr method?
- Await is a reserved word error inside async function
- WordPress Bootstrap Handburger Menu Wont Open
- Javascript WP Object Documentation?
- Show only images and videos in a wp.media window
- WordPress Rest API
- Instantiate TinyMCE via JS ( rather than PHP/wp_editor )
- Animations are not being triggered on Scroll
- Prevent escaping javascript in visual editor
- JavaScript in WordPress Customizer
- @wordpress/components Button variants not styled
- Only displaying zip files with wp media
- Button insert link on front wp_editor not working
- How Can I Add OnClick Event To A Specific WordPress Menu Link
- Adding a Javascript slideshow to the home page
- List of JS Events for Widgets?
- Authentication with the Rest API when using an External Application
- Screen Resolution Detect
- How to add customizer control via javascript ( wp.customizer.control.add )
- Override do_item() Function to Add Extra Attribute to Scripts
- Is it possible to pass js variable to template file
- Automatically Add Defer or ASYNC to all JS files (no matter where they are located)
- How to generate the COOKIEHASH from JavaScript
- Uncaught ReferenceError: jQuery is not defined – although jQuery is loaded [closed]
- How can I import one custom block into another?
- Gutenberg Blocks: how to determine an index of the current inner block?
- find out reason of “Updating failed” in Post-editor
- Getting a variable inside foreach from PHP to JS after localization
- Problem after upgrade to 3.6.1
- How to import a JavaScript Library into WordPress
- How to change the link address from internal to external
- Uncaught TypeError: Cannot read property ‘add’ of undefined bp-plupload.min.js
- When adding google tag script in website, functionality not working
- How should I identify the inline javascript that is the dependent of a wp_enqueue_script?
- How to verify that a field has a value before adding a term to a taxonomy
- List unused javascript for easy removal
- Include Facebook Javascript SDK In WordPress
- How can I look at/edit what’s being sent to post.php when I hit the publish/update button?