Template literals | Template strings

Template literals in ES6 (EcmaScript) allows us to embed expressions to our string literals. We can use multi-line strings and string interpolation features with them.

Template literals are enclosed by the back-tick (` `) instead of double or single quotes.

var message = `single line string`;
console.log(message);

// single line string

We can include place holders for string substitution using ${ } syntax

var expression = "place holder"; // string substitution
console.log(`this is a text with ${expression} in a line`);

// this is a text with place holder in a line

We can directly use expression interpolation to embed inline math

var a = 5;
var b = 5;

console.log(`the addition of a+b = ${a+b}`);
// the addition of a+b = 10

We can also call functions and use member functions in strings

function sample() { return "text from sample method"; }

console.log(`yes! ${sample()} and i am in uppercase`.toUpperCase());

// YES! TEXT FROM SAMPLE METHOD AND I AM IN UPPERCASE

The above code retrieves data from sample() method and converts it to uppercase in run-time.

Multiline Strings

We can achieve multi line strings, previously we used to insert new line character in our string

console.log(`First line
Second line`);
// First line 
// Second line

Raw strings

The special raw property, available on the first function argument of tagged template literals, allows you to access the raw strings as they were entered.

String.raw`Hi \n ${2+3}!`;
// "Hi \n 5!"

Tagged template literals

A more advanced form of template literals are tagged template literals. With them we able to modify the output of template literals using a function. The first argument contains an array of string literals. The second, and each argument after the first one, are the values of the processed substitution expressions. We can use any name to our function.

var a = 1;
var b = 2;

function tag(strings, ...values) {
 console.log(strings[0]); // "One "
 console.log(strings[1]); // " Two"
 console.log(strings[2]); // " Three"
 console.log(values[0]); // 1
 console.log(values[1]); // 2
}

tag`One ${ a } Two ${ b } Three`;

// One 
// Two 
// Three
// 1
// 2

Happy exploring EcmaScript 🙂

100 Web Project Ideas

Whenever I start learning a new Language or Framework, I used to create small apps or programs to practice.

Always, I try to build ToDo app if I learn Web Framework or random number generator if it a programming language and guess the number game.

I wish to build a list of items to help beginners to practice when they are learning something new.

So here is my contribution.

I have created a GitHub repo to list 100 Web Project Ideas

https://github.com/PandiyanCool/100-project-ideas

I wish you should help me to reach this list to more people who actually in need.

Feel free to star or fork or send PR to the repository.

And if you are using Twitter, send me hi to motivate me. I love it.

Here is a twitter thread I have created to reach more Devs.

That’s for now.

Hey @pandiyan_cool I just checked out your #100WebProjects list.

If you are reading or trying this, do let me know. I will be very happy.

Cheers, Happy Coding!

Topics

  1. Quote generator
  2. Todo app
  3. Countdown timer
  4. Stopwatch
  5. Flip a coin app
  6. World clock dashboard
  7. Good morning slack bot
  8. Daily Journal bot
  9. Mail composer UI
  10. Interactive login form
  11. Offline page in PWA
  12. Toaster message
  13. Color picker jumbtron
  14. RSS Feed viewer
  15. Json viewer
  16. Syntax highlight
  17. Json to csv
  18. Simple calculator UI
  19. Free image library
  20. Messaging to webhook
  21. Leave reason generator
  22. Visual web bookmarker
  23. Pomodoro timer
  24. Css ruler
  25. Instagram logo in css
  26. BAFFLE effect in css
  27. Motivation bot
  28. Twitter hash tag viewer
  29. Minimalist twitter profile page
  30. Minimalist github profile page
  31. Site map into flex layout
  32. Twitter bot to fav your replies
  33. Twitter bot to welcome new followers
  34. Twitter bot to send weekly report
  35. Gif search engine
  36. Good first issue hunter
  37. One download page for your fav exe
  38. Virtual site map for fav sites
  39. PWA – funny sounds directory
  40. PWA – Scolding app if late sleep
  41. PWA – Stress burster – tap me 20 times in 3 seconds
  42. PWA – Internet connection game
  43. Quotes instead of loader
  44. Comments thread UI
  45. API document with swagger json
  46. Terminal effect in css
  47. CLI for daily activities
  48. Npm library to do text operation
  49. Quiz minimalist UI
  50. Yes or No fact checking UI
  51. Render Google map for location
  52. Selfie app with frames
  53. Flames game
  54. Guess the number game
  55. Sound match game
  56. Snake game
  57. Flight time check app
  58. Weather app
  59. Time sheet app
  60. Fan simulator
  61. Css loader
  62. Minimalist resume
  63. Virtual Visiting card
  64. Custom Birthday cards
  65. Work log app (punch machine)
  66. Catch me bug game
  67. Guess the card game
  68. Clipboard history
  69. Smiley UI mock
  70. Instagram story mock
  71. Tinder suggestion mock
  72. Fake api
  73. Pinterest view for github project
  74. CheatSheet generator
  75. Social media activities dashboard
  76. Birthday reminder
  77. Reminder app if you are leaving late at work
  78. Recipe tracker
  79. Sarcasm meter
  80. Why not analog calendar?
  81. Movie rating at one place
  82. Bookshelf
  83. Energy drainer visualisation
  84. YAGNI checklist
  85. Tweet scheduler mock
  86. Image crop tool
  87. Windows blue screen error page
  88. Never seen 404 page
  89. Sarcastic 401 page
  90. Play music when page offline
  91. Render tweet into gif
  92. CSS blob maker
  93. Cute animals video search results
  94. Mock duckduckgo results page
  95. 1000 pixels custom image
  96. Swappable 5×5 grids
  97. Moments celebration timer
  98. Youtube subscribers count mock
  99. Subscribe and bell icon gif
  100. A Perfect portfolio ✌️