DEV Community

SIYAMALA G
SIYAMALA G

Posted on

String - JS

String - A string is a sequence of characters in single quotes ('), double quotes ("), or backticks (`).

javascript
const firstName = "Siyamala";
const lastName = 'Manikandan';
const message =
Welcome to JavaScript`;

console.log(firstName);
console.log(lastName);
console.log(message);
`

OutPut
plaintext
Siyamala
Manikandan
Welcome to JavaScript

1.Length
returns the total number of characters in a string.
javascript
const language = "JavaScript";
console.log(language.length);

OutPut
plaintext
10

2.Uppercase
convert all characters to uppercase.
javascript
const text = "javascript";
console.log(text.toUpperCase());

Out
JAVASCRIPT
`markdown
**3.Lowercase

convert all characters to lowercase.

`
const text = "JAVASCRIPT";
console.log(text.toLowerCase());
`
plaintext

OutPut
`
javascript
`
markdown
4.Access Characters
Use the index position to access individual characters.
`
const word = "Coding";
console.log(word[0]);
console.log(word[3]);
`
plaintext

OutPut
`
C
i
`
markdown
5.indexOf()
returns the Character Position
`
const text = "JavaScript";
console.log(text.indexOf("S"));
`
plaintext

OutPut
`
4
`
markdown
6.includes()
used to check whether a specific value exists in an array
`
const course = "JavaScript Basics";
console.log(course.includes("Script"));
`
plaintext
OutPut
`
true
`
markdown
7.replace()
replaces the first matching value.
`
const sentence = "I love Java";
const result = sentence.replace("Java", "JavaScript");
console.log(result);
`
plaintext

OutPut
`
I love JavaScript
`
markdown

8.slice()
extracts a portion of a string.
`
const text = "JavaScript";
console.log(text.slice(0, 4));
`
plaintext

OutPut
`
Java
`
markdown

9.split()
Convert a string into an array.
`
const fruits = "Apple,Banana,Mango";
console.log(fruits.split(","));
`
plaintext

OutPut
`
["Apple", "Banana", "Mango"]
`
markdown

10.trim()
remove whitespace from both ends.
`
const username = " Sherin ";
console.log(username.trim());
`
plaintext

OutPut
`
Sherin
`
markdown
11.repeat()
repeats a string a specified number of times.
`
console.log("Hi ".repeat(3));
`
plaintext

OutPut
`
Hi Hi Hi
`

Top comments (4)

Collapse
 
algorhymer profile image
algorhymer

Heyho!

I pressed a like on this article, because I hope you'll do 2 favors for me with regards to this very article:

  • Please revisit the markdown. I know this sounds dumb and hoi poloi from me, but the formatting problems really turned me off.
  • Please devote a section to string concatenation's performance. In most languages, pure string concatenation is really wasteful. Surprisingly in JS, this is not always the case. A lot of burned out PhDs were thrown at this problem. I think honoring their work with a small section would be a cool 'salute'.

Learning Java , Javascript , Automation Testing, SQL ,SDLC and modern QA practices every day.

Have you ever considered that dev.to has a ton of dev related articles,
but - not so surprisingly since devs have zero idea about how testing works and cannot even write good unit tests - testing related articles are scarce.
Aka you might consider gunning for the 'testing' niche with your next articles, as it is a more fertile ground than JS Beginner articles.

TL;DR I think you can provide more value with the same effort of work put in it, by chaning the subject towards testing, and automated testing.

Most important thing though:
I like the profile pic, but it'd be cooler if you could change the background into flames.
Oh... and also... years ago when I worked with QA contractors... they told me stories about the singing pillars of Hampi, James Bond Island, their culture's architectural and graphical obsession with wheels, and one of the more senior guys gave me a 1 hour laughter and joke filled presentation about how jainism might help my microfauna in my tummy so I can do the dailys in a less grumpy manner. I adhered to some advices, unfortunately I cannot go on a meat-free diet, because my ancestors developed a cuisine which is basically 99% meat. Everything in my country contains either meat or fat. I think even lollipops have traces of dried meat in them. It is like Eating Meat: The Country.
What I'm trying to say is that... I don't know your local of origin, but weaving in your culture might make the otherwise dry technical write ups more funnier and memorable on a human level.

Collapse
 
siyamala_g profile image
SIYAMALA G

Thank you so much for taking the time to read my article and leave such detailed feedback. I really appreciate it.

You're absolutely right about the formatting. I'll revisit the Markdown and improve the readability of the article.

I also like your suggestion about adding a section on string concatenation performance. That's an interesting topic, and I'll consider including it in an update or a future article.

Regarding your advice on writing about testing and automation, that's actually the direction I'm interested in. Since I'm learning Java, JavaScript, SQL, SDLC, and Automation Testing, I plan to share more testing-related content as I gain more experience. Thanks for encouraging me to focus on that niche.

😄 And thanks for the compliment about my profile picture! I'll think about the flames.

I also appreciate what you said about weaving cultural stories into technical articles. That's a unique suggestion, and I'll definitely try to make my future posts more personal and engaging.

Thanks again for your thoughtful feedback and encouragement. It means a lot, and I'll use your suggestions to improve my future articles.

Collapse
 
algorhymer profile image
algorhymer

Little bit of a clarification:
I worked mostly with contractors from India, so I only have a little bit of experience about that.
What was weird to me, is that people from India kind of grow up in that culture, and think for some reason that it is not really interesting.
For me, personally, it was mindboggling to hear the stories about the education system there.
It was also really funny for me how old traditions like days long wedding ceremonies live side-by-side with k-pop.
I actually rofl-ed, when a person told me stories about ancient temple layouts, then segwayed into the korean boy band BTS.
Or how some person can tell me how he manages his close-family life adhering to both his side of the big family, and his wife's side of big family, then to finally admit that sometimes - in secret team builders once a year - he lets off the stress with cigars and whiskey.

In the country I live, most of our culture and history is forgotten.
There are no deeper traditions.
Most people shop and sleepwalk their entire lives, so we leave this world exactly as rootless as we were when we started it as a baby.
So for me, it was both entertaining and interesting to see how life can be different in a country, which is fully modern, but still managed to keep some of its cultural 'spine'.

Thread Thread
 
siyamala_g profile image
SIYAMALA G

Thank you for sharing that. It was genuinely interesting to read your perspective.

I think one reason many Indians don't always find these things interesting is because we grow up surrounded by them. Things like festivals, large family gatherings, temple traditions, or even long wedding ceremonies become so normal that we rarely stop to think about how unique they might seem to someone from another culture.

At the same time, India changes very quickly. It's completely normal for someone to visit an ancient temple in the morning, listen to BTS or Western music in the afternoon, and spend the evening discussing the latest technology. Most of us don't really see those things as contradictory—they're simply different parts of everyday life.

Of course, India is incredibly diverse, so everyone's experience is different. But I'm glad you found our mix of tradition and modern life interesting. Reading your observations also reminds me not to take those parts of my own culture for granted.