dev-resources.site
for different kinds of informations.
JavaScript: String Template Literals
Published at
8/3/2024
Categories
javascript
strings
stringtemplateliterals
cleancode
Author
meganpaffrath
Author
13 person written this
meganpaffrath
open
String template literals give us a cleaner way to concatenate our strings and variables.
Let's say we have 5 hens and 3 roosters.
let hens = 5;
let roosters = 3;
We want to print out "We have 8 chickens, 5 of which are hens and 3 of which are roosters."
We could say:
let str = "We have " + (hens+roosters) + " chickens, " + hens + " of which are hens and " + roosters + " of which are roosters.";
// str = 'We have 8 chickens, 5 of which are hens and 3 of which are roosters.'
Or we could say
let str = `We have ${hens + roosters} chickens, ${hens} of which are hens and ${roosters} of which are roosters.`
// str = 'We have 8 chickens, 5 of which are hens and 3 of which are roosters.'
The second way of making this string is easier to both code and read!
strings Article's
30 articles in total
trimMiddle() - the missing String trim method
read article
Interpolação, Verbatim String Literals, Múltiplas Linhas – Tudo Sobre Strings no C#
read article
Leetcode — 3110. Score of a String
read article
Tipos Básicos em Kotlin - String Literals
read article
Tipos Básicos em Kotlin - Strings
read article
Quick Zig and C String Conversion Conundrums
read article
Code Smell 261 - DigiCert Underscores
read article
JavaScript: Strings, String Methods, and String Properties
read article
JavaScript: String Template Literals
currently reading
Top 7 PHP Strings Interview Questions and Answers
read article
Strings in java language
read article
Strings in java language
read article
Unraveling the Power of Strings in Python
read article
What to use instead of `@ember/string`
read article
JS Challenge: Check if a string is a palindrome
read article
5 Interesting Things About Strings in Java
read article
Efficient String Splitting in Go: A Solution for Gophers Dealing with API Responses
read article
Javascript : 12 méthodes essentielles pour les chaînes de caractères
read article
anagram program in java
read article
How to convert String to Integer in java
read article
JS Blog - String Manipulation
read article
Find the Index of the First Occurrence in a String (Naive and KMP Solutions)
read article
In search of subsequence
read article
383. Ransom Note
read article
Split and Join: The Dichotomy of Strings and Arrays
read article
How do Bytes live in Solidity and coexist with Strings?
read article
"str and String in Rust confuses a lot of people in the beginning"
read article
W3Schools Strings Method With Example
read article
Javascript Tagalog - Strings
read article
Resources(R.string) in viewModel in Android
read article
Featured ones: