With the arrival of Template Literals, it’s finally super easy to produce multi-line strings. Previously, we had to use the
\n or separate string concatenation which was messy and difficult to read. Finally, it’s easier now. ES6 for the win 🙌
// Old way const multiLine1 = "1️⃣first \n2️⃣second"; // ✅ ES6 way const multiLine2 = `1️⃣first 2️⃣second`; /* RESULT 1️⃣first 2️⃣second */
I just want to make sure I clarify that when I say “Multi-Line”, I mean the output of the string is spanning on multiple lines. For example, if I
console.log the variable, it will produce something like this:
// Multi-Line 1️⃣first 2️⃣second
And here’s a “Single-Line” output:
// Single-Line 1️⃣first 2️⃣second
**Ex. Using **
const notTrueMultiLine = '1️⃣first' + '2️⃣second' + '3️⃣three'; console.log(notTrueMultiLine); // 1️⃣first2️⃣second3️⃣three
**Ex. Using **
const notTrueMultiLine = "\ 1️⃣first \ 2️⃣second \ 3️⃣three"; console.log(notTrueMultiLine); // 1️⃣first2️⃣second3️⃣three
Even though, it may appear in your code as multi-line. But when it’s outputted, it’s actually a single-line. To create true multi-line output, you have to use Template Literals or
So template literals will output as it appears, spaces and all! Because of that, be mindful of your blank spaces or lines.
const blankSpace = ` first second third `;
Here’s the output. I denoted the white space with a dot, ⚪️ and line break with a square ◻️:
□ first ····second ··third □ □
This is my favorite use case of using template literals multi-string capability. It makes super readable and easy to render HTML markup. I remember before, the only way to do this is to use a template system such as Handlebars.js. Well, not anymore. We can achieve the same result without importing anything and just use vanilla JS. It’s awesome! Anyhoo, let’s take a look at some examples:
✅Ex. HTML Markup using Template Literals
const HTMLmarkup = ` <article> <h1>Code Tidbits</h1> </article> `;
const HTMLmarkup = "<article>" + "<h1>Code Tidbits</h1>" + "</article>";
Ex. HTML Markup using Handlebars.js
<script id="entry-template" type="text/x-handlebars-template"> <article> <h1>Code Tidbits</h1> </article> </script> <!-- also need to import handlebars -->
📺 The video in this post was made by Programming with Mosh
The origin of the article: https://www.youtube.com/watch?v=09BwruU4kiY&list=PLTjRvDozrdlxEIuOBZkMAK5uiqp8rHUax&index=6
🔥 If you’re a beginner. I believe the article below will be useful to you ☞ What You Should Know Before Investing in Cryptocurrency - For Beginner
⭐ ⭐ ⭐The project is of interest to the community. Join to Get free ‘GEEK coin’ (GEEKCASH coin)!
☞ **-----CLICK HERE-----**⭐ ⭐ ⭐
Thanks for visiting and watching! Please don’t forget to leave a like, comment and share!
A multi-cloud approach is nothing but leveraging two or more cloud platforms for meeting the various business requirements of an enterprise. The multi-cloud IT environment incorporates different clouds from multiple vendors and negates the dependence on a single public cloud service provider. Thus enterprises can choose specific services from multiple public clouds and reap the benefits of each.
Given its affordability and agility, most enterprises opt for a multi-cloud approach in cloud computing now. A 2018 survey on the public cloud services market points out that 81% of the respondents use services from two or more providers. Subsequently, the cloud computing services market has reported incredible growth in recent times. The worldwide public cloud services market is all set to reach $500 billion in the next four years, according to IDC.
By choosing multi-cloud solutions strategically, enterprises can optimize the benefits of cloud computing and aim for some key competitive advantages. They can avoid the lengthy and cumbersome processes involved in buying, installing and testing high-priced systems. The IaaS and PaaS solutions have become a windfall for the enterprise’s budget as it does not incur huge up-front capital expenditure.
However, cost optimization is still a challenge while facilitating a multi-cloud environment and a large number of enterprises end up overpaying with or without realizing it. The below-mentioned tips would help you ensure the money is spent wisely on cloud computing services.
Most organizations tend to get wrong with simple things which turn out to be the root cause for needless spending and resource wastage. The first step to cost optimization in your cloud strategy is to identify underutilized resources that you have been paying for.
Enterprises often continue to pay for resources that have been purchased earlier but are no longer useful. Identifying such unused and unattached resources and deactivating it on a regular basis brings you one step closer to cost optimization. If needed, you can deploy automated cloud management tools that are largely helpful in providing the analytics needed to optimize the cloud spending and cut costs on an ongoing basis.
Another key cost optimization strategy is to identify the idle computing instances and consolidate them into fewer instances. An idle computing instance may require a CPU utilization level of 1-5%, but you may be billed by the service provider for 100% for the same instance.
Every enterprise will have such non-production instances that constitute unnecessary storage space and lead to overpaying. Re-evaluating your resource allocations regularly and removing unnecessary storage may help you save money significantly. Resource allocation is not only a matter of CPU and memory but also it is linked to the storage, network, and various other factors.
The key to efficient cost reduction in cloud computing technology lies in proactive monitoring. A comprehensive view of the cloud usage helps enterprises to monitor and minimize unnecessary spending. You can make use of various mechanisms for monitoring computing demand.
For instance, you can use a heatmap to understand the highs and lows in computing visually. This heat map indicates the start and stop times which in turn lead to reduced costs. You can also deploy automated tools that help organizations to schedule instances to start and stop. By following a heatmap, you can understand whether it is safe to shut down servers on holidays or weekends.
#cloud computing services #all #hybrid cloud #cloud #multi-cloud strategy #cloud spend #multi-cloud spending #multi cloud adoption #why multi cloud #multi cloud trends #multi cloud companies #multi cloud research #multi cloud market
(‘ ’) and double quotes
(“ ”) were the only ways to make a string. Template literals offer another way to declare strings that makes use of backtick
Let’s now look at the template literals in detail.
Template literals use enclosing backticks
(``) instead of using single
(‘ ’) or double
(“ ”) quotes as shown in the following example:
Template literals use backticks
) instead of single or double quotes to declare strings
Using the backticks allows us to use the single or double quotes in the template literal without escaping because each type of character only needs to escape its own type. So, in template literals, we only need to escape backticks by using a backslash
( \ ).
Template literals do not need to escape single or double quotes
We have seen examples of how to create strings with single quotes, double quotes, and backticks. Now we will see more examples showing the advantages of using template literals.
So, head over to your terminal and create a folder LineThroughEffect. Create three files -index.html, main.js and styles.css inside it. We are also opening the files in VS Code.
Now, we will add the basics html in index.html and also link both css and js files. We have very little html in this project, with div with id of line and an h1 with an id of text.